[Django] #33499: {% url '...' test=a %} fails when "a" contains a forward slash

12 views
Skip to first unread message

Django

unread,
Feb 6, 2022, 4:54:04 PM2/6/22
to django-...@googlegroups.com
#33499: {% url '...' test=a %} fails when "a" contains a forward slash
-------------------------------------------------+------------------------
Reporter: Antônio Martos Harres | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (URLs) | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------------+------------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/33499>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 8, 2022, 3:18:10 AM2/8/22
to django-...@googlegroups.com
#33499: {% url '...' test=a %} fails when "a" contains a forward slash
-------------------------------------+-------------------------------------
Reporter: Antônio Martos | Owner: nobody
Harres |
Type: Uncategorized | Status: closed

Component: Core (URLs) | Version: 3.2
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* status: new => closed
* resolution: => wontfix


Comment:

Hi Antônio...

> if you pass a `{"category": "something/"}`

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 want `something%2F`, I think you need to pass
that yourself.)

Thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/33499#comment:1>

Django

unread,
Feb 8, 2022, 3:18:53 AM2/8/22
to django-...@googlegroups.com
#33499: {% url '...' test=a %} fails when "a" contains a forward slash
-------------------------------------+-------------------------------------
Reporter: Antônio Martos | Owner: nobody
Harres |
Type: New feature | Status: closed

Component: Core (URLs) | Version: 3.2
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* type: Uncategorized => New feature


--
Ticket URL: <https://code.djangoproject.com/ticket/33499#comment:2>

Reply all
Reply to author
Forward
0 new messages