Skip to content

Instantly share code, notes, and snippets.

@rodrigobertin
Created July 1, 2019 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigobertin/15e2c9ef6914e2af6ddfeeb9979bfc71 to your computer and use it in GitHub Desktop.
Save rodrigobertin/15e2c9ef6914e2af6ddfeeb9979bfc71 to your computer and use it in GitHub Desktop.
Form loop flask peewe
def form_loop(form, show_label=False):
try:
rend = u"""
{{ form.hidden_tag() }}
{% for field in form if field.widget.input_type !='hidden' %}
<fieldset data-iden="{{ field.name }}">
{% if show_label %}
{{ field.label }}
{% endif %}
{{ field(class='form-control', placeholder= field.description if field.description else field.name | capitalize) }}
{% if field.errors %}
{% for error in field.errors %}
<div class="alert alert-danger">{{ error }}</div>
{% endfor %}
{% endif %}
</fieldset>
{% endfor %}
"""
return render_template_string(rend, form=form, show_label=show_label)
except:
return u'Error loop_form() {}'.format(str(sys.exc_info()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment