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

MenoTx picture MenoTx · Jun 3, 2018 · Viewed 11.6k times · Source

I have configured my python env with python 3.5, but I am getting the following error when I run my server with the command python manage.py runserver

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

this is my config

dj-database-url==0.5.0
Django==2.1a.1
gunicorn==19.8.1
numpy==1.14.3
psycopg2==2.7.4
pytz==2018.4
whitenoise==4.0b4

I tried reinstalling my env and changing python version but issue stills happening.

Thanks for your questions guys

Answer

Venkatesh Gotimukul picture Venkatesh Gotimukul · Apr 19, 2019
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.