4
in settings.py you can sett logout redirect url
Give this a try
LOGOUT_REDIRECT_URL = '/path_to_the_page'
LOGIN_URL = '/path_to_the_page'
1
Solved! It turns out the logout template MUST be named logged_out.html to work in this context. When I renamed it from logout.html the page redirected properly to the custom logout template.
- [Django]-Thumbnails in the django admin panel using sorl
- [Django]-Django Admin Remove default save message
- [Django]-Issue while creating Foreign Key constraint
- [Django]-Boolean True/False/None
1
Just change the templates HTML file name with logged_out.html
Here is my logout.html template.
> Here is my logged_out.html template.
- [Django]-Django ORM equivalent for this SQL..calculated field derived from related table
- [Django]-Averaging scores in database (Django)
- [Django]-Django admin upload and image to s3 and then resize the image and save a thumb problem
- [Django]-Custom response for invalid token authentication in Django rest framework
- [Django]-Cannot import ASGI_APPLICATION module 'myproject.routing'
0
in your settings you can do that easily how suppose you have function based view
def hello(request):
return render (request, 'logout_redirect.html')
and in url
path('hello/', views.hello, name="hello")
so in your settings do this
LOGIN_URL = 'accounts:login'
LOGIN_REDIRECT_URL = 'accounts:home'
LOGOUT_REDIRECT_URL = 'accounts:home'
and second way just pass in your views
@login_required
def user_logout(request):
logout(request)
return redirect('accounts:login')
both the type is neccessary to be in your page first is for if a user logout from admin panel tell where to go and second for a custom user to tell where he have to redirect so you can change your logout redirect url different for both diffrent type of user or if you want to redirect on same url for both of the user pass the same path
and i do recommend you to read the full documentation of django for better iunderstanding
https://docs.djangoproject.com/en/3.2/topics/auth/default/