简体   繁体   中英

Django LogoutView redirect to previous page

I am using Django's auth.LogoutView class in my urls.py. I can redirect the user to a specific page using LogoutView.as_view(next_page='main:index') after logout. If I left out the next_page part, it redirects to a Django admin interface with a thank you message and a option to login again, which is the admin login page. I want to redirect the user to the page they were on before clicking the logout url on the navbar.

in your seettings.py file, add

LOGOUT_REDIRECT_URL = '/'

your logout views:

from django.contrib.auth.models import User, auth
from yourprojectName import settings

def logout(request):
    auth.logout(request)
    return redirect(settings.LOGOUT_REDIRECT_URL)

Try this:

next_page = request.get_full_path()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM