Python编程-从入门到实践 第19章 创建用户账户错误提示
本人环境:django 2.1.1
按照书中代码一字不改的打出来,会报如下错误
url(r'^login/$',login,{'template_name':'users/login.html'},name='login'), NameError: name 'login' is not defined
百度一番后,修改后如下,运行正常
from django.conf.urls import url 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') ]