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!
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'),
...
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With