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')),
And this is my template file:
{% if user.is_authenticated %}
logged in as {{ user }}
(<a href="{% url "logout" %}">logout</a>)
{% else %}
I have also enabled the default django admin site. When I click logout
, it shows me the administration logout view. How can I pass the logout next page attribute to tell django which view to render?
If you are seeing the log out page of the Django administration site instead of your own log out page (your_application/templates/registration/logged_out.html), check the INSTALLED_APPS setting of your project and make sure that django.contrib.admin comes after 'your_application'. Both templates are located in the same relative path and the Django template loader will use the first one it finds.
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.
According to docs, you can supply the next_page parameter to the logout view. https://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.views.logout
(r'^logout/$', 'django.contrib.auth.views.logout',
{'next_page': '/logged_out/'})
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