Django'django.contrib.auth.views'没有属性'login'

时间:2019-05-21 18:49:26

标签: python django django-views django-authentication

当我尝试从django.contrib.auth导入视图时出现此属性错误,我想使用其身份验证方法

from django.contrib import admin
from django.urls import path
from django.conf.urls import url,include
from django.contrib.auth import views

urlpatterns = [
    url(r'', include('blog.urls')),
    url(r'^accounts/login/$', views.login, name='login'),
    url(r'^accounts/logout/$', views.logout, name='logout', kwargs= 
{'next_page':'/' }),
    path('admin/', admin.site.urls),
]

AttributeError:模块'django.contrib.auth.views'没有属性'login'

url(r'^ accounts / login / $',views.login,name ='login'),

1 个答案:

答案 0 :(得分:1)

Django auth.view模块不具有login功能。

尝试一下(Django 2.2)

from django.contrib.auth.views import LoginView, logout_then_login, LogoutView


url(r'^accounts/login/$', LoginView.as_view(), name='login'),
url(r'^accounts/logout/$', LogoutView.as_view(), name='logout'),

or 

url(r'^accounts/login/$', logout_then_login, name='login'),