django logout redirects me to administration page

前端 未结 11 2111
生来不讨喜
生来不讨喜 2020-12-14 14:32

I have provided a simple login functionality. For logout, I tried to use the built-in one. This is my urls.py:

(r\'\', include(\'django.contrib.auth.urls\'))         


        
11条回答
  •  天命终不由人
    2020-12-14 15:26

    Tested on Django 1.6:

    What I do is adding this into my urls.py:

    (r'^management/logout/$', 'django.contrib.auth.views.logout'),
    

    And then used it:

    Log out
    

    For the next argument, there you point to the right URL.

    Tested on Django 2.1

    Append to urlpatterns in urls.py:

    from django.contrib.auth import views as auth_views
    
    urlpatterns = [
        path('logout/', auth_views.LogoutView.as_view(), name='logout'),
    ]
    

    And then use it in the template:

    logout
    

    More info can be found here.

提交回复
热议问题