What's wrong with my django url?
line from urls.py:
url(r'^(?P<customer_profile_id>\d+)/case/(?P<account_type>\w+)/$', view='case', name='case'),
line from html:
<form method="POST" action="{% url 'case/cash/' %}" id="create_collection_case" target="_blank">
Mistake:
NoReverseMatch at /admin/customers/1/
Reverse for 'case/cash/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
I just have a html form -> submit to django url -> loading django view. I am getting the above error when loading the page. Let me know if you need anything else for troubleshooting!
+3
source to share
2 answers
Your regex must match the form's action perfectly if you want django to define a route. Note that \d+
represents integers and I prefer to match texts / strings with ([-\w+]+)
.
For best practices, I advise you to change the url again (it is always better to have an integer query value at the end)
url(r'^case/(?P<account_type>[-\w+]+)/(?P<customer_profile_id>\d+)/$', view='case', name='case'),
and your form action should accept this where profile_id is an integer
{% url 'case/cash/profile_id/' %}
#e.g. http://127.0.0.1:8000/case/cash/1/
0
source to share