Display value of a django form field in a template?

Posted by Eran Kampf on Stack Overflow See other posts from Stack Overflow or by Eran Kampf
Published on 2010-02-10T12:24:53Z Indexed on 2010/04/21 1:53 UTC
Read the original article Hit count: 319

Filed under:
|

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="[email protected]" 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 errorneous value ("[email protected]" in this example) to the user. How do I get the field's value in the template?

© Stack Overflow or respective owner

Related posts about django

Related posts about django-templates