Django-registration Forbidden(403)CSRF验证失败。请求中止

时间:2016-08-16 15:51:09

标签: python django django-registration django-csrf

安装django-registration-redux后,每次尝试注册时都会出现403 CSRF错误。这是我的form.html:

{% extends "base.html" %}
{% load i18n %}
{% load crispy_forms_tags %}



{% block content %}
<div class="space"></div>
<div class="space"></div>
<div class="space"></div>
<div class="space"></div>
<div class='row'>
<div class='col-sm-6 col-sm-offset-3'>
<h1>Înregistrare</h1>
<form method="post" action=".">
  {% csrf_token %}
  {{ form|crispy }}

  <input class='btn btn-block btn-primary' type="submit" value="{% trans 'Join' %}" />
</form>
</div>
</div>

<hr/>
<div class='row'>
<div class='col-sm-6 col-sm-offset-3 text-align-center'>
<p>Doriți să vă <a href="{% url 'auth_login' %}">Logați</a>?</p>
</div>
</div>


{% endblock %}

1)是的,我在form.html和以下的MIDDLEWARE_CLASSES中都有{%csrf_token%}:

= (
    'djangosecure.middleware.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

1 个答案:

答案 0 :(得分:1)

我将django从1.8升级到1.10后出现同样的问题。 降级到1.8修复问题(暂时)..