title: Django POST request failing
body: <p>I get an error while using a POST in my form even though I have added a csrf_token to my form....</p>
  
  <p>Error</p>
  
  <p>Forbidden (403)</p>
  
  <p>CSRF verification failed. Request aborted.</p>
  
  <p>Help</p>
  
  <p>Reason given for failure:
      CSRF cookie not set.</p>
  
  <p>In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django's CSRF mechanism has not been used correctly. For POST forms, you need to ensure:
  •Your browser is accepting cookies.
  •The view function uses RequestContext for the template, instead of Context.
  •In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
  •If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.</p>
  
  <p>You're seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed. </p>
  
  <p>You can customize this page using the CSRF_FAILURE_VIEW setting.</p>
  
  <pre><code>views.py
  
  def search_form(request):
      return render_to_response('search_form.html')
  def search(request):
      print 'request.post=', request.POST
      print 'request.get=', request.GET
      print 'request.method=', request.META.get('REQUEST_METHOD')
      if 'q' in request.GET:
          message = 'You searched for :%r' % request.GET['q']
      else:
          message = 'You submitted an empty form'
  
      return HttpResponse(message)
  
  
  
  search-form.html
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Search&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action="/polls/search/" method="post"&gt;{% csrf_token %}
          &lt;input type="text" name="q"&gt;
          &lt;input type="submit" value="Search"&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  urls.py
  urlpatterns = patterns('',url(r'^$',views.index,name='index'),
          url(r'^meta/',views.display_meta,name='meta'),
          url(r'^search-form/$',views.search_form),
          url(r'^search/',views.search),
  </code></pre>