Code

Opened 7 years ago

Closed 6 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:

Description

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.

So:

{% 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 7 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 7 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 7 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 7 years ago by PhiR

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

comment:3 Changed 7 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 7 years ago by PhiR

  • Owner changed from nobody to PhiR

comment:5 Changed 7 years ago by PhiR

  • Status changed from new to assigned

comment:6 Changed 6 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).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.