machineghost
machineghost

Reputation: 35813

Combining "with" and "url" Django Template Tags

Django has two template tags "with" and "url". It would be handy to be able to combine the two:

{% with view=really.long.path.to.some.view.somewhere %}
    {% url view.foo %}
{% endwith %}

But if you try doing that, you find out that the "with" isn't getting applied inside the "url" tag (as you get an error about there not being a "view.foo").

So, my question is, am I just missing some flag/option/alternative format that would make the above work, or is truly impossible to simplify "url" tags using "with"?

Upvotes: 1

Views: 471

Answers (1)

Simeon Visser
Simeon Visser

Reputation: 122456

It is possible in Django 1.3 if you're willing to use a future compatibility library.

See the section Forwards compatibility at https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url (just above the discussion on widthratio) for an explanation and examples.

Upvotes: 2

Related Questions