我正在学习教程,但注销不起作用,我有这样的东西。(蟒蛇 3.7(
from django.contrib.auth import views as auth_views
urlpatterns = [
# Auth
url(r'^logout/', auth_views.logout, name='logout'),
]
我收到此错误(未运行(:
AttributeError: module 'django.contrib.auth.views' has no attribute 'logout'
我还检查了在同一路径上是否有一个名为auth_logout()
的函数,但它需要request
才能工作,我不知道该怎么做。它在没有参数的情况下运行,当我调用 url 时它会注销,但我得到一个异常:
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'),
视图模块没有注销功能。下面的代码应该可以工作。
urlpatterns = [
url(r'^logout/', auth_views.LogoutView.as_view(), name='logout'),
]