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\'))
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.
I'm surprised no one has mentioned this, you can put this in your settings.py to redirect when logging in and logging out:
LOGIN_REDIRECT_URL = '/go-here-after-login/'
LOGOUT_REDIRECT_URL = '/go-here-after-logout/'
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/'})
This is all fairly well explained in the manual, is there anything specific you don't understand?
https://docs.djangoproject.com/en/dev/topics/auth/default/#how-to-log-a-user-out
from django.contrib.auth import logout
def logout_view(request):
logout(request)
# Redirect to a success page.
Alternatively if you don't want to create your own view
https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.views.logout
{% url 'logout' next='/some/url/' %}
Go to settings.py and add this code. "/" will redirect you to home
# Where to redirect during authentication
LOGIN_REDIRECT_URL = "/" #To go to home after login instead of getting redirected to accounts/profile on login which is default
LOGOUT_REDIRECT_URL = "/" #To logout back to the home page instead of the default admin logout page