[Django] #35616: "url" template tag works with a context variable only if left unquoted

2 views
Skip to first unread message

Django

unread,
Jul 18, 2024, 4:23:25 PM7/18/24
to django-...@googlegroups.com
#35616: "url" template tag works with a context variable only if left unquoted
-----------------------+-------------------------------------------
Reporter: Pzdrs | Type: Uncategorized
Status: new | Component: Template system
Version: 5.0 | 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
-----------------------+-------------------------------------------
I tried passing a context variable as the url_name parameter like so:

{{{
{% url 'url' %}
}}}

Django raises a NoReverseMatch exception - Reverse for 'url' not found.
'url' is not a valid view function or pattern name.

When left unquoted like so:

{{{
{% url url %}
}}}

PyCharm gives me a warning (View names should be in quotes since Django
1.5 and should have no quotes before 1.5) despite Django apparently
accepting this and resolving to the correct URI.

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

Django

unread,
Jul 19, 2024, 3:39:25 AM7/19/24
to django-...@googlegroups.com
#35616: "url" template tag works with a context variable only if left unquoted
---------------------------------+--------------------------------------
Reporter: Petr Boháč | Owner: (none)
Type: Uncategorized | Status: closed
Component: Template system | Version: 5.0
Severity: Normal | Resolution: invalid
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 Sarah Boyce):

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

Comment:

Hi Petr, in the
[https://docs.djangoproject.com/en/5.0/ref/templates/builtins/#url
documentation for url], there is a warning:

> Don’t forget to put quotes around the URL pattern name, otherwise the
value will be interpreted as a context variable!

In this case, you want it to be treated as a context variable and so not
adding quotes is correct and adding them treats it as a view name.
This is working as expected to me and the behaviour is documented. Please
feel free to give feedback to PyCharm 👍
--
Ticket URL: <https://code.djangoproject.com/ticket/35616#comment:1>
Reply all
Reply to author
Forward
0 new messages