Opened 5 months ago
Closed 5 months ago
#35616 closed Uncategorized (invalid)
"url" template tag works with a context variable only if left unquoted
Reported by: | Petr Boháč | Owned by: | |
---|---|---|---|
Component: | Template system | Version: | 5.0 |
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
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
Note:
See TracTickets
for help on using tickets.
Hi Petr, in the documentation for url, there is a warning:
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 👍