xadmin icon indicating copy to clipboard operation
xadmin copied to clipboard

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

Open Mark110 opened this issue 7 years ago • 13 comments

when I runserver,I take the error ImportError: cannot import name 'login' from 'django.contrib.auth.views' .why?

Mark110 avatar Jul 17 '18 04:07 Mark110

same problem, any solution?

yxc20089 avatar Jul 20 '18 00:07 yxc20089

same problem, any solution?

kuangshp avatar Aug 02 '18 00:08 kuangshp

same probleme

xadmin don't work with django 2.1.0 but it's work with django 2.0.7

gpoignon avatar Aug 07 '18 17:08 gpoignon

It is located in django.contrib.auth (cut out the .views). It seems to have been moved in 2.1...

Can't find 'password_reset' though!

Craigk0001 avatar Aug 08 '18 20:08 Craigk0001

These are deprecated with 2.1 in favour of class based views. see https://docs.djangoproject.com/en/2.1/internals/deprecation/ and https://docs.djangoproject.com/en/2.1/releases/1.11/#deprecated-features-1-11

rowinggolfer avatar Aug 23 '18 14:08 rowinggolfer

Same problem, fixed as Craig said and I'm trying to find password_reset too

nicogaspa avatar Aug 25 '18 14:08 nicogaspa

nicogaspa, from the links I posted

contrib.auth’s password_change(), password_change_done(), password_reset(), password_reset_done(), password_reset_confirm(), and password_reset_complete() function-based views are deprecated in favor of new class-based views PasswordChangeView, PasswordChangeDoneView, PasswordResetView, PasswordResetDoneView, PasswordResetConfirmView, and PasswordResetCompleteView.

rowinggolfer avatar Aug 25 '18 20:08 rowinggolfer

`from django.conf.urls import url from django.contrib.auth.views import login

from . import views

urlpatterns = [ # 登录页面 url(r'^login/$', login, {'template_name': 'users/login.html'}, name='login'), ]` This is my urls.py . As you expect, it will go wrong. I found many ways, but they didn't work. One way is that removing .views, but it also didn't work. And report errors:TypeError: login() got an unexpected keyword argument 'template_name' Because I just start learning Django, it's difficult for me to understand the Official documents. It would be better if you could tell me how to solve this problem.Thanks

Anthony521XL avatar Sep 28 '18 12:09 Anthony521XL

Anthony - this is my urls.py for my "accounts" app.

` from django.conf.urls import url

from django.contrib.auth.views import ( PasswordResetView, PasswordResetConfirmView, PasswordResetDoneView, PasswordResetCompleteView, PasswordChangeView, PasswordChangeDoneView, )

from accounts import views from accounts.views import ssl_required # decorator for contrib.auth functions

urlpatterns = ( url(r"^login", views.LoginView.as_view(), name="login"), url(r"^logout", views.LogOutView.as_view(), name="logout"), url( r"^registered", views.RegisteredView.as_view(), name="accounts-registered", ), url(r"^register", views.RegisterView.as_view(), name="accounts-register"), url( r"^my-account/(?P\d+)/$", views.UserProfileView.as_view(), name="accounts-user_account", ), url( r"^password-change$", ssl_required(PasswordChangeView.as_view()), {"extra_context": views.CONTEXT}, name="password_change", ), url( r"^password-change-done$", ssl_required(PasswordChangeDoneView.as_view()), {"extra_context": views.CONTEXT}, name="password_change_done", ), url( r"^password-reset/", ssl_required(PasswordResetView.as_view()), {"extra_context": views.CONTEXT}, name="password_reset", ), url( r"^password-reset-done", ssl_required(PasswordResetDoneView.as_view()), {"extra_context": views.CONTEXT}, name="password_reset_done", ), url( r"^password-reset-complete", ssl_required(PasswordResetCompleteView.as_view()), {"extra_context": views.CONTEXT}, name="password_reset_complete", ), url( r"^password-reset-confirm/(?P[0-9A-Za-z]+)-(?P.+)/$", ssl_required(PasswordResetConfirmView.as_view()), {"extra_context": views.CONTEXT}, name="password_reset_confirm", ), ) `

rowinggolfer avatar Sep 28 '18 12:09 rowinggolfer

@rowinggolfer Thank you very much. I solved this problem through your codes just now.

Anthony521XL avatar Sep 28 '18 13:09 Anthony521XL

`from django.conf.urls import url from django.contrib.auth.views import login

from . import views

urlpatterns = [

登录页面

url(r'^login/$', login, {'template_name': 'users/login.html'}, name='login'), ]` This is my urls.py . As you expect, it will go wrong. I found many ways, but they didn't work. One way is that removing .views, but it also didn't work. And report errors:TypeError: login() got an unexpected keyword argument 'template_name' Because I just start learning Django, it's difficult for me to understand the Official documents. It would be better if you could tell me how to solve this problem.Thanks

我也遇到了类似的问题

Desperado1001 avatar May 03 '20 07:05 Desperado1001

It is located in django.contrib.auth (cut out the .views). It seems to have been moved in 2.1...

Can't find 'password_reset' though!

It worked thank you

AFZAL58 avatar Jul 18 '20 04:07 AFZAL58

The following code also works (you need to import LoginView instead of login)...

from django.urls import path from django.contrib.auth.views import LoginView

app_name = 'users' urlpatterns = [ # Login page path('login/', LoginView.as_view(template_name='users/login.html'), name='login') ]

wlemusl avatar Aug 18 '21 01:08 wlemusl