Django cannot import login from django.contrib.auth.views

Since , the login, logout, etc. function-based views have been rewritten to class-based views: the LoginView [Django-doc] and LogoutView [Django-doc] classes, as is specified in the release notes. The “old” function-based views could still be used, but were marked as deprecated.

In , the old function-based views have been removed, as specified in the release notes.

You can write it like:

from django.contrib.auth.views import LoginView

from django.urls import path
from . import views
app_name = "users"
urlpatterns = [
    path('login/', 
        LoginView.as_view(
            template_name="users/login.html"
        ), 
        name="login"
    ),
]

Leave a Comment