Django初學者在這裏,我一直試圖解決這個很長一段時間。 我在我的中間件類中有'django.middleware.csrf.CsrfViewMiddleware',並且在我的表單中有確實的標記。CSRF令牌缺失或不正確
繼承人我的代碼,我做錯了什麼?
from django.contrib.auth.forms import UserCreationForm
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from chartsey.authentication.forms import RegistrationForm
from django.template import RequestContext
from django.core.context_processors import csrf
def register(request):
if request.method == 'POST':
c = RequestContext(request.POST, {})
form = RegistrationForm(c)
if form.is_valid():
new_user = form.save()
return HttpResponseRedirect("/")
else:
form = RegistrationForm()
return render_to_response("register.html", {'form': form, },)
這裏是我的模板:
{% block content %}
<h1>Register</h1>
<form action="" method="POST"> {% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit">
</form>
{% endblock %}
的可能重複註釋掉下面的行[Django的:CSRF令牌丟失或不正確(http://stackoverflow.com/questions/8321217/ django-csrf-token-missing-or-incorrect) – lracicot