title: remembering form field value on django model form
body: <p>I am quite new to Django as such, and have been playing around with ModelForms. So far, I have been able to create ModelForms with ease. However, one problem seems to bug me a bit:</p>
  
  <p>When a user fills the form, and if there is an error (say <code>int</code> instead of <code>char</code> or a missing <code>blank=False</code> value), the form spits out the error and seems to <em>forget</em> the values the user entered when the form failed to validate. I am wondering if there is a way to <em>remember</em> these values so that the user does not have to enter them again.</p>
  
  <p>At the moment, I have something like the following:</p>
  
  <pre><code>class ContactForm(CreateView):
  
      form_class = ContactForm
      template_name = "superform.html"
      success_url = '/ty/'
  
      def form_valid(self, form):
          # do something useful with validated form
          return super(ContactForm, self).form_valid(form)
  
      def form_invalid(self, form):
          # do something useful with invalidated form.
          return super(ContactForm,self).form_invalid(form)
  </code></pre>
  
  <p>I am assuming I need to do something in <code>form_invalid</code> to pass the values back to the form - but I am unsure how to do this(?). </p>
  
  <p>I would really appreciate if someone could point me in the right direction.</p>
  
  <p>Thanks.</p>
  
  <p>--<em>--Edit---</em></p>
  
  <pre><code>            &lt;form class="form" role="form" action="{% url 'coolurl' %}" method="post"&gt;{% csrf_token %}
  
                      {% if form.non_field_errors %}
                        &lt;div class="alert"&gt;
                        {% for error in form.non_field_errors %}
                        &lt;span class="label"&gt;Error: {{ error|escape }}&lt;/span&gt; 
                        {% endfor %}
                        &lt;/div&gt;
                      {% endif %}
  
  
                      &lt;div class="form-group"&gt;
                          {% if form.name.errors %}
                            &lt;div class="alert"&gt;
                            {% for error in form.name.errors %}
                            &lt;span class="label"&gt;Error: {{ error|escape }}&lt;/span&gt; 
                            {% endfor %}
                            &lt;/div&gt;
                          {% endif %}
  
                          &lt;label class="col-sm-3" for="id_name"&gt;Name:&lt;/label&gt;
                          &lt;div class="col-sm-6"&gt;
                          &lt;input class="form-control" 
                               id="id_name" 
                               type="text" 
                               name="name" 
                               maxlength="128" 
                               placeholder="Your name.."&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
  
                      &lt;button type="submit" class="btn btn-success"&gt;Submit&lt;/button&gt;
              &lt;/form&gt;
  </code></pre>