Django logout problem

后端 未结 5 1760
轻奢々
轻奢々 2021-02-09 08:05

Here is the problem I am facing with the Django Authenetication

  1. Access a page that requires a login.
  2. Logout (accessing django.contrib.auth.logout)
  3. <
相关标签:
5条回答
  • 2021-02-09 08:14

    Basically, this should work:

    from django.contrib.auth import logout
    
    def logout_view(request):
        logout(request)
        # Redirect to a success page.
    

    Could you clarify by posting your view if it's not something like this?

    0 讨论(0)
  • 2021-02-09 08:14

    Change session expire on close to False, with true it will not log you out until you close the browser

    0 讨论(0)
  • 2021-02-09 08:28

    This worked for me. I was too stuck with this problem. Found the following solution on youtube.

    My solution is a little modified though.

    in views.py

    from django.contrib.auth import authenticate, login, logout
    from django.shortcuts import redirect
    
    def auth_logout(request):
      logout(request)
      return redirect('home')
    

    in urls.py

    url(r'^logout$', views.auth_logout, name='auth_logout'),  
    
    0 讨论(0)
  • 2021-02-09 08:34

    views

    from django.contrib.auth import logout

    def logout_user(request):

    """
        logout the user
    """   
    
    logout(request)
    return HttpResponseRedirect('/qioness/connect/')
    

    urls:

    url(r'^userlogout/$',logout_user),
    

    worked 4 me

    0 讨论(0)
  • 2021-02-09 08:36

    In Django 1.4.* I've had problems with the logout() function. It simply wasn't logging out my users.

    Now I'm just using the contributed view to logout users and it works perfectly. Simply add this to your root urls.py file if you don't want to do anything else special:

    (r'^logout/$', 'django.contrib.auth.views.logout', {'next_page': '/login'}),
    

    and you'll be good to go.

    Happy Djangoing.

    0 讨论(0)
提交回复
热议问题