line from urls.py:
来自urls.py的行:
url(r'^(?P<customer_profile_id>\d+)/case/(?P<account_type>\w+)/$', view='case', name='case'),
line from html:
来自html的行:
<form method="POST" action="{% url 'case/cash/' %}" id="create_collection_case" target="_blank">
error:
NoReverseMatch at /admin/customers/1/
Reverse for 'case/cash/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
I just have an html form -> posting to a django url -> loading a django view. I get the above error when loading the page. Let me know if you need anything else to troubleshoot!
我只是有一个html表单 - >发布到django url - >加载django视图。加载页面时出现上述错误。如果您需要其他任何问题进行排查,请告诉我们!
1
Specify the name of the url (case
), not the part of the url:
指定url(case)的名称,而不是url的部分:
<form method="POST" action="{% url 'case' %}" id="create_collection_case" target="_blank">
0
Your regular expression needs to match perfectly with the form action if you want django to determine the route. Please note that \d+
represents integers and I prefer to match texts/strings with ([-\w+]+)
.
如果您希望django确定路线,则您的正则表达式需要与表单操作完美匹配。请注意\ d +表示整数,我更喜欢将文本/字符串与([ - \ w +] +)匹配。
For best practises I will advice you change your URL re to (always best to have your integer query value at the end)
对于最佳实践,我建议您将URL重新更改为(总是最好在结尾处使用整数查询值)
url(r'^case/(?P<account_type>[-\w+]+)/(?P<customer_profile_id>\d+)/$', view='case', name='case'),
and your form action should take this, where profile_id is an integer
并且您的表单操作应采用此方法,其中profile_id是整数
{% url 'case/cash/profile_id/' %}
#e.g. http://127.0.0.1:8000/case/cash/1/
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2015/06/27/cdfd0ee7bf565d4d8ef623aaa6081568.html。