I'm learning flask and Python along w/ HTML and CSS. I've got a Flask template to render a dropdown.
What I need to do is this: When you select a value from the dropdown/picklist, print that out on the same page. if I then select a new value in the picklist, print that value, etc. etc.
I can get the picklist in the template but can't get that value passed back into the template.
Below is my code.
{% block content %}
<div class="table-responsive">
<table class="table">
<select name="Item_1">
{% for y in obj %}
<option value="{{ y }}">{{ y }}</option>
{% endfor %}
</select>
</table>
</div>
<div>
<!-- THIS IS WHERE I NEED TO PRINT THE VALUE {{ y }} AS SOON AS I SELECT IT -->
</div>
{% endblock %}
and the app.py code
@app.route('/index', methods=['GET','POST'])
def index():
svc = beatbox.Client()
svc.login(login, pw)
desc = svc.describeSObjects('Opportunity')
listOfObjects = getObjects()
#BELOW IS THE SECTION I'M CONFUSED ABOUT, HOW DO I GET printValue INTO THE TEMPLATE DYNAMICALLY?
printValue = request.form.get['Item_1']
return render_template("indexes.html",
obj=listOfObjects,
#printValue = printValue)
what you are asking for is when you change the value on the client to update the html with the selected value. For this you need to add a bit of jquery javascript to achieve this. Basically you want dynamically update the html.
Scroll down to see the demo.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.