Django注销问题 [英] Problems with Django logout

查看:36
本文介绍了Django注销问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注一个教程,但是注销无法正常工作,我有类似的内容.(Python 3.7)

I was following a tutorial, but the logout is not working, I have something like this. (Python 3.7)

from django.contrib.auth import views as auth_views

urlpatterns = [
# Auth
url(r'^logout/', auth_views.logout, name='logout'),
]

我收到此错误(无法运行):

I get this error (doesn't run):

AttributeError: module 'django.contrib.auth.views' has no attribute 'logout'

我还检查了同一路径上是否有一个名为 auth_logout()的函数,但是它需要一个 request 才能工作,而且我不知道该怎么做那.它不带参数运行,当我调用url时,它确实注销了,但出现异常:

I also checked that there is a function called auth_logout() on that same path, but it needs a request to work, and I have no idea how to do that. It runs without the parameter and when I call the url it does logout, but I get an exception:

The view django.contrib.auth.logout didn't return an HttpResponse object. It returned None instead.

欢迎任何帮助.谢谢.

推荐答案

尝试:

    from django.contrib.auth import logout

    url(r'^logout/', logout, name='logout'),

或者您可以尝试:

    from django.contrib.auth import views as auth_views

    url(r'^logout/', auth_views.LogoutView.as_view(), name='logout'),

这篇关于Django注销问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆