【发布时间】:2015-11-12 23:17:21
【问题描述】:
我认为这可能是非常简单的事情,但我一生都无法弄清楚为什么这些网址不匹配。
我的模板代码如下所示:
<form action="{% url 'view_record' "facility_report" %}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="View Report" name='view' label="Submit"> </form>
然后该 url 应该与我的 url conf 中的这一行匹配:
url(r'^view_record/((?P<report_type>.+)/)?$', views.view_record, name='view_record'),
我在这里缺少什么?它们根本不匹配,有关此的大多数其他问题都来自五年前,当时引擎似乎对格式更加挑剔。
Exception Type: NoReverseMatch at /view_record/
Exception Value: Reverse for 'view_record' with arguments '('facility_report',)' and keyword arguments '{}' not found. 1 pattern(s) tried: ['view_record/((?P<report_type>(.*))/)?$']
【问题讨论】:
-
你能显示你的views.py文件吗?
-
回溯说什么?
-
这是一个反向 url 匹配错误,尝试发布的 url 后无法匹配 '('facility_record',)'。我会贴出确切的日志并立即查看。
-
好的,添加了错误信息。视图实际上相当大,据我所知与错误无关。
-
您能说出您在视图中传递的论点吗?
标签: python django django-templates django-urls