views:

66

answers:

1

Hi All,

What I'd like to do (for a recent changes 'widget' - not a django widget in this case) is pass a urlname into my template as a variable, then use it like so: {% url sitechangeobject.urlname %} Where urlname is a string containing a valid name for a url.

Is this possible? The template keeps breaking saying it can't find sitechangeobject.urlname as a name (which is quite right, it doesn't exist). Is there any way to make it look inside that variable?

There are other ways to solve this problem if not, just thought I'd check though.

Thanks!

+2  A: 

The built-in url tag cannot do this. However django-reversetag does exactly this (and more).

According to the readme, the reverse tag provided by this code provides:

  • Consistent syntax ("string literals" and variables)
  • Ability to reverse view names stored in context variables
  • Partial reversing
msanders
That looks very useful - thank you very much for pointing it out.
Ninefingers