This is the Category.py to create fields
class CategoryForms(FlaskForm):
cat_choices = [('sport', 'sport'),('music',music')]
categories = SelectedMultipleField('Categories' choices = cat_choices)
submit=SubmitField('Lets Go!')
This is the Category.html that displays the fields
<form action ='' method='Post'>
{{form.hidden_tag}}
<p>
{{form.categories.label}}
{{form.categories)row=3 multiple=True}
</p>
<p>
{{form.submit()}}
</p>
<form>
The routes.py
@app('category, methods['GET','POST'])
def category():
form = CategoryForms()
if request.method =='POST':
if form.is_submitted():
result = form.categories.data
return render_template('cat-request.html', result=result)
return render_template('category.html', title='Category', form = form)
My issue are:
1) The select options only allow for one section and not multiple. 2) When getting the user input, I did a for loop but nothing displays. Is this the right approach? Like below:
in the cat-request.html file
{% for value in result %}
{{value}}
{% endfor %}