[Django]-Logging out on django web app redirects to django admin logout page. What's going on?

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.

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.

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/

Leave a comment