I am following this tutorial http://flask.pocoo.org/docs/0.10/patterns/wtforms/
Here’s an example _formhelpers.html template with a macro:
{% macro render_field(field) %}
<dt>{{ field.label }}
<dd>{{ field(**kwargs)|safe }}
{% if field.errors %}
<ul class=errors>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</dd>
{% endmacro %}
Here the register.html template which takes advantage of the _formhelpers.html template:
{% from "_formhelpers.html" import render_field %}
<form method=post action="/register">
<dl>
{{ render_field(form.username) }}
{{ render_field(form.email) }}
{{ render_field(form.password) }}
{{ render_field(form.confirm) }}
{{ render_field(form.accept_tos) }}
</dl>
<p><input type=submit value=Register>
</form>
It ends up generating a sequence of those:
<dt><label for="email">Email Address</label>
<dd><input id="email" name="email" type="text" value="">
I want to put more parameters and in a bit different fashion like:
<input type="email" id="email" name="email" class="input-xlarge"
placeholder="Email Address" value="{{ form.email }}"
required>
How do I modify
<dt>{{ field.label }}
<dd>{{ field(**kwargs)|safe }}
to achieve that?
Coming from the documentation you can do:
{{ form.email(class_="input-xlarge",
placeholder="Email Address",
value="[email protected]") }}
Which will render:
<input type="email" id="email" name="email" class="input-xlarge"
placeholder="Email Address" value="[email protected]"
required>
Just replace "[email protected]" with form.email without braces as you are already inside them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With