Sometimes, we want to set default form values with Python Django.
In this article, we’ll look at how to set default form values with Python Django.
How to set default form values with Python Django?
To set default form values with Python Django, we can set the initial
argument of the form constructor to a dict with the initial values.
For instance, we write
form = JournalForm(initial={'tank': 123})
to create a JournalForm
instance with the initial
argument set to {'tank': 123}
to set the field with name tank
to initial value 123.
Conclusion
To set default form values with Python Django, we can set the initial
argument of the form constructor to a dict with the initial values.