I have a form with an email property.
When using {{ form.email }} in case of some validation error, Django still renders the previous value in the input tag’s value attribute:
<input type="text" id="id_email" maxlength="75" class="required"
value="some@email.com" name="email">
I want to render the input tag myself (to add some JavaScript code and an error class in case of an error). For example this is my template instead of {{ form.email }}:
<input type="text" autocomplete="on" id="id_email" name="email"
class="email {% if form.email.errors %} error {% endif %}">
However, this does not display the erroneous value (some@email.com in this example) to the user.
How do I get the field’s value in the template?
The solution proposed by Jens is correct.
However, it turns out that if you initialize your ModelForm with an instance (example below) django will not populate the data:
So, I made my own ModelForm base class that populates the initial data:
Then, the simple view example looks like this: