以下是模板中相关的 HTML 片段:
<form action="/submit_text/" method="post">
{% csrf_token %}
{% include "backbone/form_errors.html" %}
{{form.as_p}}
<input type="submit" value="Submit" />
</form>
这是我的settings.py
MIDDLEWARE_CLASSES
声明:
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',
)
CSRF 令牌根本不显示,导致
禁止 (403) CSRF 验证失败。请求中止。