Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django settings LOGOUT_REDIRECT_URL doesn't work

Tags:

python

django

I'm using Django 1.8.7 with the following apps installed:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bootstrap3',
'myapp',
'storages',
'rest_framework',
'django_tables2',]

I use the built-in django.contrib.auth.urls to create my pages for login, password change, etc. I set my LOGOUT_REDIRECT_URL in the settings.py to '/home', exactly like I did with LOGIN_REDIRECT_URL. Logging out a user via the page works fine, but I stil remain at the logout page afterwards. This is not a problem when logging in, the login redirect works like it should.

a part of my urls.py:

url(r'^accounts/', include('django.contrib.auth.urls'), {'template_name': 'registration/login.html'}),

my settings.py:

LOGIN_REDIRECT_URL = '/home'
LOGOUT_REDIRECT_URL = '/home'

Thanks in advance for any help or ideas!

like image 790
Nkls155 Avatar asked Feb 28 '17 12:02

Nkls155


1 Answers

The LOGOUT_REDIRECT_URL setting was added in Django 1.10.

On earlier versions of Django, you can set next_page in your URL pattern for the logout view.

from django.conf import settings
from django.conf.urls import url
from django.contrib.auth import views

url_patterns = [
    ...
    url(r'^logout/$', views.logout, {'next_page': settings.LOGOUT_REDIRECT_URL}, name='logout'),
    ...
]
like image 75
Alasdair Avatar answered Sep 20 '22 13:09

Alasdair