Answers for "django set form field value in template"

0

django set form field value in template

This was a feature request that got fixed in Django 1.3.

Here's the bug: https://code.djangoproject.com/ticket/10427

Basically, if you're running something after 1.3, in Django templates you can do:

{{ form.field.value|default_if_none:"" }}
Or in Jinja2:

{{ form.field.value()|default("") }}
Note that field.value() is a method, but in Django templates ()'s are omitted, while in Jinja2 method calls are explicit.

If you want to know what version of Django you're running, it will tell you when you do the runserver command.

If 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
Posted by: Guest on March-23-2021

Code answers related to "django set form field value in template"

Python Answers by Framework

Browse Popular Code Answers by Language