Django-退出登录功能

1、新增url

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^login/', views.login),
    url(r'^login_action/', views.login_action),
    url(r'^event_manage/', views.event_manage),
    url(r'^accounts/login',views.login),
    url(r'^search_name/',views.search_name),
    url(r'^search_phone/',views.search_phone),
    url(r'^guest_manage/',views.guest_manage),
    url(r'^sign_index/(?P<event_id>[0-9]+)/$',views.sign_index),
    url(r'^sign_index_action/(?P<event_id>[0-9]+)/$', views.sign_index_action),
    url(r'^logout/',views.logout)
]

2、views里面增加views.logout函数

@login_required
def logout(request):
    auth.logout(request)
    response = HttpResponseRedirect('/login/')   #重定向到首页
    return response

3、python3 manage.py runserver启动后,访问:http://127.0.0.1:8000/login/登录后点击退出

源代码:https://github.com/Oneperson1128/DjangoDemo.git  参考loginDemo8文件夹 

posted @ 2021-02-20 17:16  Yi个人  阅读(96)  评论(0编辑  收藏  举报