Python NoReverseMatch at/accounts/login/form操作查询?

Python NoReverseMatch at/accounts/login/form操作查询?,python,django,Python,Django,我正在努力学习django,但我在任何地方都找不到答案,或者至少不能简单地说!我试图在我的项目中实现包含的登录视图,我尝试使用文档中使用的示例html,我得到了这个错误 Template error: In template C:\Users\Owner\Documents\django\mysite\templates\registration\login.html, error at line 14 Reverse for 'login' with arguments '()' and

我正在努力学习django,但我在任何地方都找不到答案,或者至少不能简单地说!我试图在我的项目中实现包含的登录视图,我尝试使用文档中使用的示例html,我得到了这个错误

Template error:
In template  
C:\Users\Owner\Documents\django\mysite\templates\registration\login.html, error at line 14
Reverse for 'login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []   4 : 
5 : {% if next %}
6 :     {% if user.is_authenticated %}
7 :     <p>Your account doesn't have access to this page. To proceed,
8 :     please login with an account that has access.</p>
9 :     {% else %}
10 :     <p>Please login to see this page.</p>
11 :     {% endif %}
12 : {% endif %}
13 : 
14 : <form method="post" action=" {% url 'login' %} ">
15 : {% csrf_token %}
16 : <table>
17 : <tr>
18 :     <td>{{ form.username.label_tag }}</td>
19 :     <td>{{ form.username }}</td>
20 : </tr>
21 : <tr>
22 :     <td>{{ form.password.label_tag }}</td>
23 :     <td>{{ form.password }}</td>
24 : </tr>
这是我的mysite/url.py文件:

from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views

urlpatterns = [
url(r'^polls/', include('polls.urls', namespace="polls")),
url(r'^blog/', include('blog.urls', namespace="blog")),
url(r'^admin/', admin.site.urls),
url(r'^accounts/login/$', auth_views.login),
]
我已经在表单的action字段中尝试了accounts/login,这会产生相同的错误。任何想法都将不胜感激!谢谢

Action=“{%url”login“%”:这意味着在提交表单时,您将在url.py中搜索名为“login”的url并执行该视图。但是在url.py中没有任何名为login的内容。您可以尝试将url.py的最后一行编辑为: url(r“^accounts/login/$”,auth_views.login,name='login'), 或将模板文件编辑为:

您是否尝试查看该页面?
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.auth import views as auth_views

urlpatterns = [
url(r'^polls/', include('polls.urls', namespace="polls")),
url(r'^blog/', include('blog.urls', namespace="blog")),
url(r'^admin/', admin.site.urls),
url(r'^accounts/login/$', auth_views.login),
]