#3668 closed (duplicate)
URL tag should accept variable, a quoted literal
| Reported by: | Owned by: | Adrian Holovaty | |
|---|---|---|---|
| Component: | Template system | Version: | dev |
| Severity: | Keywords: | URL tag | |
| Cc: | not.com@… | Triage Stage: | Design decision needed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I'm building up menus in django, and wanted a construct like this:
[[[
{% for item in menu %}
<a href="{% url item.view%}">{{item.label}}</a>
]]]
but that doesn't work, because there's no view "item.view"
That looks like a shortcoming/inconsistancy with the syntax of the URL tag. With most tags, an unquoted item gets looked up, and a quoted item is used as-is. Here, there's no way to look up the first argument to URL.
Suggested solution: require quotes for a literal (eg [{% url 'myapp.views.summarize_widgets' %}], and allow view names to be passed with the usual django syntax (eg [{% url item.some_view %}])
Change History (3)
comment:1 by , 19 years ago
| Triage Stage: | Unreviewed → Design decision needed |
|---|
comment:2 by , 19 years ago
| Resolution: | → duplicate |
|---|---|
| Status: | new → closed |
Dupe of #3796 (has more discussion)
+1 from me.