我正在尝试使用django登录视图实现登录页面,这里是代码:
urls.py
urlpatterns = patterns( '', url(r'^login/$', 'django.contrib.auth.views.login'), url(r'^logout/$', 'django.contrib.auth.views.logout'), )
和模板:
的login.html
{% extends 'base_cost_control.html' %} {% block contentbase %} {% if form.errors %}{% endblock contentbase %}Invalid user or password
{% endif %}
所以,我知道django.contrib,auth.views.login生成视图,我只需要创建login.html模板,但我在login.html的第8行收到此错误:
Reverse for 'login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
我不知道还能做什么......
您尚未命名登录URL,因此您无法通过名称对其进行反转login
.只需将名称添加到模式:
from django.contrib.auth import views as auth_views urlpatterns = [ url(r'^login/$', auth_views.login, name='login'), url(r'^logout/$', auth_views.logout, name='logout'), ]