Django settings LOGOUT_REDIRECT_URL doesn't work

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'),
    ...
]

As per Django 2.1 (2019), you can do something like this

1). In settings.py set LOGOUT_REDIRECT_URL = 'name of url you would like to redirect to'

2). In urls.py

import settings
from django.contrib.auth import views as auth_views

urlpatterns = [
    ...,
    path('logout/', auth_views.LogoutView.as_view(next_page=settings.LOGOUT_REDIRECT_URL), name='logout'),
    ...,
]

Tags:

Python

Django