6👍
✅
You’re calling the wrong logout
.
from django.contrib.auth import logout
should be
from django.contrib.auth.views import logout
1👍
You should import logout from views, from django.contrib.auth.views import logout
, instead of from django.contrib.auth import logout
.
On side note, for such behavior you may want to use logout signal. Refer login logout signals
- [Django]-How to connect to Azure SQL database from Django app on Linux VM
- [Django]-How to set Value of One field of Django model equal to Other field of other Django model
- [Django]-Need to override django auto_now_add in pytest factory
- [Django]-Got InvalidClientIdError (invalid_request) Mismatching redirect URI. using requests_oauthlib
- [Django]-TruncDate timezone parameter is not working in Django
0👍
I got the same problem as you and used this simple workaround:
views.py:
def my_logout(request):
# Staff you want to do before logout
from django.http import HttpResponseRedirect
return HttpResponseRedirect("/logout2/")
urls.py:
(r'^logout/$', 'views.my_logout'),
url(r'^logout2/$',
django.contrib.auth.views.logout,
{'template_name': 'logged_out.html'}, # Next page
name='auth_logout'),
- [Django]-How to run Daphne and Gunicorn At The Same Time?
- [Django]-How to send a email from a form django
- [Django]-Django unique combination of foreign keys
0👍
This has become a problem with the Django V2. You could define your login and logout functions in views and call them in the urls. Or you can follow the example given in the Django Documentation
from django.contrib.auth import views as auth_views
path(‘accounts/login/’, auth_views.LoginView.as_view()),
Source:stackexchange.com