I get the 403rd, version of python 2.6, django 1.4 like this, transferring the data to the template
from django.http import HttpResponse from django.core.context_processors import csrf from django.shortcuts import render_to_response def index(request): c = {} c.update(csrf(request)) if 'q' in request.POST: q = request.POST['q'] return render_to_response('index.html', c) else: return render_to_response('index.html', {'q': 'error', 'c': c} )
in the pattern: {{q}}
<form action="" method="POST" /> {% csrf_token %} <input type="text" name="q" /> <input type="submit"> </form>
settings.py
.... MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', # Uncomment the next line for simple clickjacking protection: # 'django.middleware.clickjacking.XFrameOptionsMiddleware', ) ....
All that is needed is done, but I still receive the CSRF verification failed. Request aborted .