i have this html form where user can choose name from a list :
{% block main %}
<form action="/ballot" method="post">
1st Choice
<select name="name1">
<option disabled selected value="">name</option>
{% for candidate in candidates %}
<option value={{ candidate }}>{{ candidate["name"] }}</option>
{% endfor %}
</select><div></div>
In python, i request for this data "name1" using this code
name1= request.form['name1']
return "Username is " name1
And the result is below : Username is {'id':
Note that "{'id':" is nowhere in my code
How do i get the correct value from html form
CodePudding user response:
On your for loop value must be between ":
Try editing from this
<option value={{ candidate }}>{{ candidate["name"] }}</option>
To this:
<option value="{{ candidate }}">{{ candidate["name"] }}</option>