user2387135
user2387135

Reputation: 99

Display the post data after error in django and html5

django form

{% for field in form.fields %}
    {{field}}
  </div>
{% endfor %}

If there is an error {{field.email}} will output this html with a post data value

<input id="id_email" type="text" value="gffdg" />

I want to use HTML 5 inputs but don't know how to get the post value if there is error

<input id="id_email" type="email" >

edit..

I was hoping not to use widgets with my django forms and just type the html5 code in my template (type="email" not type="text")

<input id="id_email" type="email" >`

but can't figure out how to get the value back after a post with errors.

<input value="?????" />

Upvotes: 1

Views: 449

Answers (1)

arocks
arocks

Reputation: 2882

If you are trying to get the bound value of the email field, then the following template code should work:

<input id="id_email" type="email" value="{{ form.email.value }}">

If the value is not set, then it will be a blank field.

Upvotes: 1

Related Questions