Python from django.contrib.auth.views import logout ImportError: cannot import name 'logout'

ImportError: cannot import name 'login' from 'django.contrib.auth.views'

I had this error and looked up for a solution found it here. Remove views from import

Works for me in Python 3.7 and Django 2.2. No need to downgrade to Django 2.0.4(as LTS is in 2.2)

It was this one that caused me the error.

from django.contrib.auth.views import login

Had to change it to

from django.contrib.auth import login

Worked for logout too.


Hey looks like you are using the wrong django version, django.contrib.auth.views.logout is not available in your current django version, try downgrading your django version to a lower version with this command: sudo pip install Django==2.0.2 or change the import in order to use logout_view


settings.py

LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'

urls.py

from django.conf.urls import url
from django.contrib.auth.views import LogoutView

urlpatterns = [
    url(r'^logout$', LogoutView.as_view(), name='logout'),
]

it's work for me on django 3.0.x