I have provided a simple login functionality. For logout, I tried to use the built-in one. This is my urls.py:
(r\'\', include(\'django.contrib.auth.urls\'))
Summary of the most common solutions:
Make sure that your_app comes before django.contrib.admin in your INSTALLED_APPS list in your settings.py file.
Also make sure that your log out page is called 'logged_out.html' as pointed out in the answers above. Mine was called logout.html and didn't work.
Just replace loaders here, and auth templates will be found in "your_progect_apps/templates/registration":
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
],
},
},
]
Django v2.1
The easiest solution is:
Make sure your app comes before django.contrib.admin
under installed apps in settings.py
.
Make sure your template is called logged_out.html
.
i was experiencing the same isssue following Django by example... found this url worked for me
url(r'^logout/$', 'django.contrib.auth.views.logout', { 'template_name': 'account/logout.html',}, name='logout' ),
You can put LOGOUT_REDIRECT_URL
in your settings.py
file with a url name to redirect to, e.g. LOGOUT_REDIRECT_URL = 'index'
Tested on Django 1.6:
What I do is adding this into my urls.py
:
(r'^management/logout/$', 'django.contrib.auth.views.logout'),
And then used it:
<a href="{% url "django.contrib.auth.views.logout" %}?next=/">Log out</a>
For the next
argument, there you point to the right URL.
Tested on Django 2.1
Append to urlpatterns
in urls.py
:
from django.contrib.auth import views as auth_views
urlpatterns = [
path('logout/', auth_views.LogoutView.as_view(), name='logout'),
]
And then use it in the template:
<a href="{% url "logout" %}?next=/">logout</a>
More info can be found here.