title: How to write good form validation in Django?
body: <p>I've seen Django's samples and I can see they have decent error handling. However I want to see if there is yet a better approach, a general pattern to handle form validation errors in Django. This is the sample I found <a href="http://docs.djangoproject.com/en/dev/topics/forms/" rel="nofollow">here</a>:</p>
  
  <pre><code>def contact(request):
      if request.method == 'POST': # If the form has been submitted...
          form = ContactForm(request.POST) # A form bound to the POST data
          if form.is_valid(): # All validation rules pass
              # Process the data in form.cleaned_data
              # ...
              return HttpResponseRedirect('/thanks/') # Redirect after POST
      else:
          form = ContactForm() # An unbound form
  
      return render_to_response('contact.html', {
          'form': form,
      })
  </code></pre>
  
  <p>In particular, I was wondering:</p>
  
  <ol>
  <li><p>How can the view in "/thanks/" be sure that the form was validated? Are there any common ways to pass the successful validation of the form to the next view? Or do I need to do something manually such as setting a flag in request's session?</p></li>
  <li><p>How can one write this code in a way that when form is NOT valid and the page is shown with errors upon submission, if user refreshes the browser it wouldn't ask the user if they want to POST data again?</p></li>
  </ol>
  
  <p><strong>EDIT:</strong> With regards to #1 I am referring to cases like user manually entering the '/thanks/' url or going back and forth through history pages and accidentally openning it without any form being validated. (Do we still show the "thanks" page? or we need to somehow re-validate why we are in thanks view).</p>