172๐
Modern Django (2017+?) has a setting called LOGOUT_REDIRECT_URL
.
Older Djangos / Original Answer
You donโt need to overwrite or wrap anything.
According to the docs, you can just supply the next_page
argument to the logout view.
https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.views.logout
(r'^logout/$', 'django.contrib.auth.views.logout',
{'next_page': '/successfully_logged_out/'})
70๐
One easier way:
Add โnextโ parameter to your log-out request url. For example:
<a href="{% url 'auth_logout' %}?next=/path_to_the_page"> Logout</a>
Then the logout view will do the trick for you.
For after-login-redirect, you can just simply set it in settings.py:
LOGIN_REDIRECT_URL = '/path_to_the_page'
LOGIN_URL = '/path_to_the_page'
- [Django]-Why does my Django admin site not have styles / CSS loading?
- [Django]-Django 1.10.1 'my_templatetag' is not a registered tag library. Must be one of:
- [Django]-Select DISTINCT individual columns in django?
- [Django]-How can I filter a date of a DateTimeField in Django?
- [Django]-Django โ Static file not found
- [Django]-Retrieving parameters from a URL
23๐
You can redirect user anywhere by using LOGOUT_REDIRECT_URL in your setting.py file
LOGOUT_REDIRECT_URL = 'url name to redirect'
- [Django]-Reload django object from database
- [Django]-Django py.test does not find settings module
- [Django]-No handlers could be found for logger
14๐
Redirect to current page
<a href="{% url 'logout' %}?next={{ request.path | urlencode }}">{% trans "Logout" %}</a>
Tested in Django 1.9.
See also: Is it possible to pass query parameters via Django's {% url %} template tag?
- [Django]-How to use Python type hints with Django QuerySet?
- [Django]-Django url tag multiple parameters
- [Django]-How to specify an IP address with Django test client?
7๐
You can even use named urls for your next parameter:
<a href="{% url 'auth_logout' %}?next={% url 'homepage' %}"> Logout</a>
- [Django]-How to duplicate virtualenv
- [Django]-How to add a cancel button to DeleteView in django
- [Django]-Django 1.8 KeyError: 'manager' on relationship
4๐
In your logout view, after you logout the user for good, return HttpResponseRedirect(url). Please see here for more details.
- [Django]-Write only, read only fields in django rest framework
- [Django]-Django: manage.py does not print stack trace for errors
- [Django]-Uninstall Django completely
3๐
From docs you can write your own logout view (which can be just simple wrapper) overriding the โnextโ page.
- [Django]-How to monkey patch Django?
- [Django]-How to iterate through dictionary in a dictionary in django template?
- [Django]-How to create a user in Django?
3๐
If you want to set the redirection URL on client level, you can do it in the urls.py
:
(r'^management/logout/$', 'django.contrib.auth.views.logout'),
And then in the template:
<a href="{% url 'django.contrib.auth.views.logout' %}?next=/">
Log out
</a>
Where the next
, you point to the right URL.
- [Django]-How to get the current URL within a Django template?
- [Django]-What is pip install -q -e . for in this Travis-CI build tutorial?
- [Django]-Negating a boolean in Django template
0๐
If you have defined your own urls (and not imported generic auth urls) and are using the standard django auth views, them you can simply add (template_name=โexample.htmlโ) in the path.
path('logout/',auth_views.LogoutView.as_view(template_name='homepage.html'),name="logout")
- [Django]-Django Generic Views using decorator login_required
- [Django]-Django error when installing Graphite โ settings.DATABASES is improperly configured. Please supply the ENGINE value
- [Django]-Auto-create primary key used when not defining a primary key type warning in Django
0๐
add this in you project setting.py file
LOGOUT_REDIRECT_URL = '/'
you can write your URL between โ
I use my index page for logout default redirect
- [Django]-.filter() vs .get() for single object? (Django)
- [Django]-In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?
- [Django]-Django-way for building a "News Feed" / "Status update" / "Activity Stream"
0๐
Add the below line in your project setting.py file:
ACCOUNT_LOGOUT_REDIRECT_URL = '/'
- [Django]-Error: No module named staticfiles
- [Django]-Filtering dropdown values in django admin
- [Django]-Django CMS fails to synch db or migrate