我无法绕过 CSRF 令牌验证 403 错误。这是我所拥有的:
看法:
from django.template import RequestContext
def add(request, name):
#logic
return render_to_response("category/add.html", {"form": form},
context_instance = RequestContext(request))
模板:
<form action="/category/add/" method="post">
{% csrf_token %}
New Category: <input type="text" name="name" id="categoryname" />
<input type="submit" value="Hinzufuegen" />
</form>
设置:
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',
)