模块“ django.contrib.auth.views”没有属性“登录”

时间:2019-04-16 19:15:36

标签: python django

我运行:python manage.py migration并出现此错误 我认为对于此版本的Django,您需要重写代码,但我不知道该怎么做。 DJANGO 2.2     模块“ django.contrib.auth.views”没有属性“登录”

我认为对于此版本的Django,您需要重写代码,但我不知道该怎么做。

这是我的代码:

File
url.py

[from django.conf.urls import url, include
from django.contrib import admin
from KisEats3app import views
from django.contrib.auth import views as auth_views

from django.conf.urls.static import static
from django.conf import settings

urlpatterns = \[
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.home, name='home'),

     Restaurant
    url(r'^restaurant/sign-in/$', auth_views.login,
        {'template_name': 'restaurant/sign_in.html'},
        name = 'restaurant-sign-in'),
    url(r'^restaurant/sign-out', auth_views.logout,
        {'next_page': '/'},
        name = 'restaurant-sign-out'),
    url(r'^restaurant/sign-up', views.restaurant_sign_up,
        name = 'restaurant-sign-up'),
    url(r'^restaurant/$', views.restaurant_home, name = 'restaurant-home'),

     Sign In/ Sign Up/ Sign Out
    url(r'^api/social/', include('rest_framework_social_oauth2.urls')),
     /convert-token (sign in/ sign up)
     /revoke-token (sign out)
\] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)][1]

1 个答案:

答案 0 :(得分:1)

使用

 from django.contrib.auth.views import LoginView

  url(r'^restaurant/sign-in/$', LoginView.as_view(template_name='restaurant/sign_in.html'),  
    name='restaurant-sign-in'),

LoginView是一个基于类的视图,因此应使用它……as_view()

在HTML中,您必须使用{{form.as_p}}来显示您的所有字段