I recently upgraded my application from Django 1.11 to Django 2.0.
I am facing an issue when trying to logging in while in the incognito mode of Google Chrome, only the first time I get: Forbidden (403) CSRF verification failed. Request aborted.
. If I resend the login post, I still getting error. But, if I go to the login page again, it works normally.
I think it is something related to cookies. My middlewares are the following:
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
]
My login view:
from django.contrib.auth.views import LoginView as AuthLoginView
class LoginView(AuthLoginView):
template_name = 'transactions/login.html'
The template transactions/login.html
:
{% extends 'base.html' %}
{% load bootstrap_tags %}
{% block content %}
<div class="col-sm-6 col-md-4 well">
<form action="{% url 'login' %}" method="post" class="form">
{% csrf_token %}
{{ form|as_bootstrap }}
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
{% endblock content %}
I assumed everything is configured correctly since this problem happens only at this scenario.
Does anybody knows what is going on?