Opened 9 years ago

Closed 9 years ago

#5408 closed (duplicate)

Url tag first argument should be able to be a context variable

Reported by: Øyvind Saltvik <oyvind@…> Owned by: PhiR
Component: Template system Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: no
Easy pickings: UI/UX:


If the first view/name argument to the url tag used a context var it would be easier to reuse in inculded templates

I have two views that takes the same kwargs i could do

{% with "someview" as myview %}
{% url myview slug=object.slug %}
{% endwith %}

Instead of writing the same code twice.


{% url "someview" slug=object.slug %}

{% url myview slug=object.slug %}

Would mean the same thing

Attachments (1)

5408.patch (6.3 KB) - added by PhiR 9 years ago.
changed url to accept vars and quoted strings for the first argument (view path)

Download all attachments as: .zip

Change History (7)

comment:1 Changed 9 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

Maybe it's useful, but it breaks the templates for anyone who has used {% url %} thusfar. If that's acceptable, then we should move this to accepted.

comment:2 Changed 9 years ago by PhiR

It would be very useful, though a clean implementation would require having a separate url_var tag that does what you ask.

Changed 9 years ago by PhiR

changed url to accept vars and quoted strings for the first argument (view path)

comment:3 Changed 9 years ago by PhiR

  • Component changed from Uncategorized to Template system
  • Has patch set
  • Needs tests set

as per discussion with devs on #django-sprint, my patch changes the url tag behavior (backward incompatible). Regression tests seem ok.

comment:4 Changed 9 years ago by PhiR

  • Owner changed from nobody to PhiR

comment:5 Changed 9 years ago by PhiR

  • Status changed from new to assigned

comment:6 Changed 9 years ago by mtredinnick

  • Resolution set to duplicate
  • Status changed from assigned to closed

This seems to be identical to what #3769 requested, so marking as a dupe (it's a massive backwards incompatible change, so would need django-dev sign-off before we implemented it).

Note: See TracTickets for help on using tickets.
Back to Top