#33499 closed New feature (wontfix)
{% url '...' test=a %} fails when "a" contains a forward slash
Reported by: | Antônio Martos Harres | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When using {% url %}, if the dictionary passed to the second parameter is dinamically generated on the template and contains a slash, it fails with a "No reverse match" error, to reproduce, do the following:
In the template (html file):
{% url 'post_list' category=category %}
In the urls.py file:
urlpatterns = [ path('posts/<str:category>/', post_list, name='post_list'), ]
Now if you pass a {"category": "something/"} to the render functionality, it will fail with a no reverse match, this is because, in the views, the matcher for anything passed in the urls cannot contain a slash, for instance, <str:category> will not match if it contains a slash
To solve this issue, I recommend enconding the slash as %2F
Change History (2)
comment:1 by , 3 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 by , 3 years ago
Type: | Uncategorized → New feature |
---|
Hi Antônio...
I think we'd just put this down to wrong usage no? The URL
path
pattern provides the trailing/
, so passing it as part of the parameter is not intended. (If you really wantsomething%2F
, I think you need to pass that yourself.)Thanks.