django set form field value in template

Solutions on MaxInterview for django set form field value in template by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "django set form field value in template"
Deshawn
25 Nov 2018
1This was a feature request that got fixed in Django 1.3.
2
3Here's the bug: https://code.djangoproject.com/ticket/10427
4
5Basically, if you're running something after 1.3, in Django templates you can do:
6
7{{ form.field.value|default_if_none:"" }}
8Or in Jinja2:
9
10{{ form.field.value()|default("") }}
11Note that field.value() is a method, but in Django templates ()'s are omitted, while in Jinja2 method calls are explicit.
12
13If you want to know what version of Django you're running, it will tell you when you do the runserver command.
14
15If you are on something prior to 1.3, you can probably use the fix posted in the above bug: https://code.djangoproject.com/ticket/10427#comment:24