在学习注册用户的过程中,视图中下面的代码
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 LoginView from . 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"), ]
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试