Difference between revisions of "Implementing HTML CheckBoxes in Jinja"

From PeformIQ Upgrade
Jump to navigation Jump to search
(Created page with "=Notes= * http://stackoverflow.com/questions/7996075/iterate-through-checkboxes-in-flask Category:Jinja")
 
 
(5 intermediate revisions by the same user not shown)
Line 2: Line 2:


* http://stackoverflow.com/questions/7996075/iterate-through-checkboxes-in-flask
* http://stackoverflow.com/questions/7996075/iterate-through-checkboxes-in-flask
* https://coderwall.com/p/pkthoa/read-checkbox-in-flask
* http://thefort.org/tag/python/  Uses WTForms
* http://webpython.codepoint.net/cgi_multiple_field_names Simple example
=Example 1=
==Template==
<pre>
{% for contact in contacts %}
    <input type="checkbox" id="id_{{contact.id}}" name="contacts" value="{{contact.id}}">
    <label for="id_{{contact.id}}">{{contact.name}}</label>
{% endfor %}
</pre>
==Flask==
<pre>
if request.method == "POST":
    selected_contacts = request.form.getlist("contacts")
</pre>
=Gotchas=
* http://nesv.blogspot.com.au/2011/10/flask-gotcha-with-html-forms-checkboxes.html


[[Category:Jinja]]
[[Category:Jinja]]

Latest revision as of 10:25, 25 December 2014

Notes


Example 1

Template

{% for contact in contacts %}
    <input type="checkbox" id="id_{{contact.id}}" name="contacts" value="{{contact.id}}">
    <label for="id_{{contact.id}}">{{contact.name}}</label>
{% endfor %}


Flask

if request.method == "POST":
    selected_contacts = request.form.getlist("contacts")

Gotchas