On Mon, 2009-03-02 at 00:02 -0800, Rama Vadakattu wrote:
> Thanks Malcolm.Understood very clearly.
> 
> Following the same approach i have used following code in my templates
> {% url djorum_feed_url   category.getCategoryString %}
> 
> category.getCategoryString is the function which returns category
> string "category/catgory.id"
> 
> 
> Regards
> rama
> 
> BUt how should i use the url tag to form the above
> Actually i need this url in my template

Well, that's a different question to the one you asked. You asked how to
do this with reverse(), which is easy, since we have the full power of
Python at our disposal. The "url" template tag, however, is a bit less
flexible (typically, template tags have less argument flexibility than
full Python functions).

Now, I'm not really sure what you're saying is the problem here. Does
the fragment you've posted not work? Providing
category.getCategoryString() can be called with no arguments and returns
a string, it should be usable in the url template tag.

Also, it shouldn't really be returning, literally,
"category/category.id", I presume. It should be returning something like
"category/1". One of the things you cannot do in templates is use a
variable to return the name of another variable to look up (which is
called indirect lookups). The template language is intentionally
restricted to not permit that.

If you cannot call getCategoryString() with no arguments, then you
cannot use the url template tag. You'll need to write your own template
tag that knows somehow how to get the appropriate category.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to