django2.3怎么导入login包
在学习注册用户的过程中,视图中下面的代码
from django.contrib.auth.views import login
启动django服务时,报错:
ImportError: cannot import name 'login' from 'django.contrib.auth.views'
改为
from django.contrib.auth import login
django服务启动正常,但在点击login链接时又出现如下错误
TypeError at /users/login/login() got an unexpected keyword argument 'template_name'
Request Method:GET
Request URL:http://127.0.0.1:8000/users/login/
Django Version:2.1.4
Exception Type:TypeError
Exception Value:
login() got an unexpected keyword argument 'template_name'
经过多方查找,解决办法如下:
from django.contrib.auth.views import LoginViewfrom . import views
app_name = 'users'
urlpatterns = [
#登录页面
#url(r'^login/$', login, {'template_name': 'users/login.html'}, name = 'login'),
url(r'^login/$', LoginView.as_view(template_name='users/login.html'), name="login"),
]
以上是 django2.3怎么导入login包 的全部内容, 来源链接: utcz.com/z/522514.html