Skip to content Skip to sidebar Skip to footer

How Can You Manually Render A Form Field With Its Initial Value Set?

I'm trying to render a form's fields manually so that my designer colleagues could manipulate the input elements within the HTML instead of struggling in Python source. ie. Instead

Solution 1:

There is an interesting long standing ticket about this very issue. There is sample code to implement a template filter in the comments that should do what you need:

http://code.djangoproject.com/ticket/10427

Solution 2:

<input value="{{form.name.data|default_if_none:'my_defaut_value'}}" ... />

You will have to use default_if_none because the implicit value of a bound field will not be stored in data.More details here

Post a Comment for "How Can You Manually Render A Form Field With Its Initial Value Set?"