Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's the key part from the django docs on <a href="https://docs.djangoproject.com/en/dev/ref/forms/api/#bound-and-unbound-forms" rel="noreferrer">bound and unbound forms</a>.</p> <blockquote> <p>A Form instance is either <strong>bound</strong> to a set of data, or <strong>unbound</strong>: </p> <ul> <li>If it’s <strong>bound</strong> to a set of data, it’s capable of validating that data and rendering the form as HTML with the data displayed in the HTML. </li> <li>If it’s <strong>unbound</strong>, it cannot do validation (because there’s no data to validate!), but it can still render the blank form as HTML.</li> </ul> </blockquote> <p>You can't really see the difference for the example form you gave, because the form is valid in the "bound data" style. Let's extend the form by adding an <code>age</code> field, then the difference will be more obvious.</p> <pre><code>class MyForm(forms.Form): name = forms.CharField() age = forms.IntegerField() </code></pre> <h2>Bound form</h2> <pre><code>my_form = MyForm({'name': request.user.first_name}) </code></pre> <p>This form is invalid, because <code>age</code> is not specified. When you render the form in the template, you will see validation errors for the <code>age</code> field.</p> <h2>Unbound form with dynamic initial data</h2> <pre><code>my_form = MyForm(initial={'name':request.user.first_name}) </code></pre> <p>This form is unbound. Validation is not triggered, so there will not be any errors displayed when you render the template.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload