Opened 18 years ago

Closed 17 years ago

#3769 closed (wontfix)

use vars in {% url %}

Reported by: Paul Rauch <LightLan@…> Owned by: Adrian Holovaty
Component: Template system Version: dev
Severity: Keywords: absolute url tag variable
Cc: not.com@…, django@… 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

atm it seems impossible to me to use vars in the template"function"

http://www.djangoproject.com/documentation/templates/#url

both {% url {{variable}} %} and {% url {{variable}} %} lead to an empty string, though variable is a valid string(app_name.views.function)

{% url app_name.views.function %} works without a prob.

Change History (10)

comment:1 by Paul Rauch <LightLan@…>, 18 years ago

ups, I ment both {% url {{variable}} %} and {% url variable %}

comment:2 by Chris Beaven, 18 years ago

Triage Stage: UnreviewedDesign decision needed

This will change functionality. How necessary is it really? It seems quite cyclic (in a redundant sort of way) that a view should pass views to context.

comment:3 by Paul Rauch <LightLan@…>, 18 years ago

I just like to create a easy configurable navigation.
and therefor stored name and links in the database.

different groups will see different links.
But without url accepting variables I'd have to hardcode every url in the database.

comment:4 by Malcolm Tredinnick, 18 years ago

This is a reasonable request. I have a feeling there's another ticket open about this, too, but I can't seem to find it at the moment.

The only slightly tricky thing here is what the solution should be. The natural fix is to make the url tag behave like every other tag: values in quotes are strings, non-quoted values are treated as variables and resolved in the current context. Unfortunately, that requires a backwards-incompatible change. Not out of the question, but not ideal. However, all the other solutions I can think of lead to inconsistent behaviour or are just impractical.

I'd like to hear Jacob or Adrians' impressions on this before going ahead and breaking systems for 1.0.

At the moment, I'm probably slightly in favour of breaking compatibility, because there's no real alternative.

comment:5 by Chris Beaven, 18 years ago

Malcom, found the other ticket (#3668) and marked as a dupe of this one.

comment:6 by yary h <not.com@…>, 18 years ago

Cc: not.com@… added

comment:7 by anonymous, 18 years ago

Cc: django@… added

comment:8 by rogerdpack, 18 years ago

Yeah the only work around seems to be...not use {% url ... %} for now. Another work around might be to make a function within the DB model that gives you the output you desire (using permalink).

This actually brings up an interesting design decision for django. I'd say the biggest weakness of the template system is that you can't seem to call arbitrary funcions, with parameters, and have that work. If you could that would be "sweet" {% func arbitrary_function_name param1, param2, {{ currentUser.id }} %}...anyway just my $.02. Not worth much but hey :)

-Roger

comment:9 by Chris Beaven, 17 years ago

Keywords: tag added

comment:10 by Malcolm Tredinnick, 17 years ago

Resolution: wontfix
Status: newclosed

This idea (using variables in url tags) didn't seem to gather any real support in a discussion on django-dev (ignore the last couple of messages which veered off into other territory).

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