[Flask] Show Value after error Flask/Wtforms

ulrich ub at artfacts.net
Wed Sep 18 11:18:04 EDT 2019


hey ben,

in your example, just add a value="{{ form.email.data }}" to your <input />.

i am sure there is an example somewhere in either flask snippets or
flask-wtform examples.

hope that helps,

ub


On 9/18/19 3:02 PM, Ben Duncan wrote:
> In Flask / Wtforms, if you fail the validation, how to
> show the values back on the web form ?
> Sample:
>
>  <div>{{ form.email.label.text }}</div>
>          <input
>                style='width: 350px;'
>                name='email'
>                id='email'
>                type='text'
>                size='30'
>           >
>         {% if form.email.errors %}
>          <ul class="errors">
>           {% for error in form.email.errors %}
>             <li>{{ error }}</li>
>         {% endfor %}
>         </ul>
>         {% endif %}
>
> with the class being defined:
> class ContactForm(FlaskForm):
>       name = StringField("Name: ", validators=[DataRequired()])
>       email = StringField("Email: ", validators=[Email()])
>
> If there was an error of any sort, I would like the form errors to be
> re-displayed...
>
> Thanks
>
> *Ben Duncan*
> DBA / Chief Software Architect
> Mississippi State Supreme Court
> Electronic Filing Division
>
> _______________________________________________
> Flask mailing list
> Flask at python.org
> https://mail.python.org/mailman/listinfo/flask
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20190918/c83cbb41/attachment-0001.html>


More information about the Flask mailing list