0

I run : python manage.py migrate and have this error I assume that for this version of Django you need to rewrite the code, but I don’t understand how. DJANGO 2.2 module 'django.contrib.auth.views' has no attribute 'login'

I assume that for this version of Django you need to rewrite the code, but I don’t understand how.

Here is my code:

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]
FRESH TRASH
  • 1
  • 1
  • 1
  • You need to use the new [class-based views](https://docs.djangoproject.com/en/2.2/topics/auth/default/#django.contrib.auth.views.LoginView).Possible duplicate of https://stackoverflow.com/questions/51906428/django-cannot-import-login-from-django-contrib-auth-views. – gdef_ Apr 16 '19 at 19:46

1 Answers1

1

use

 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 is a classbased view so it should be used ... as_view()

and in HTML you have to use {{ form.as_p }} to show up all ur fields

Jax.ajay
  • 49
  • 8