Endpoint within templates?

2 views
Skip to first unread message

Italo Maia

unread,
May 7, 2009, 8:16:48 PM5/7/09
to glashammer
In django, inside templates, i can recover a shortcut to a url with
the tag {%url shortcut %}. With glashammer, how can i do that? I
wouldn't like to hardcode any urls inside the templates.

Ali Afshar

unread,
May 7, 2009, 8:41:17 PM5/7/09
to glash...@googlegroups.com
There is a function automatically added to the Glashammer template
environment called url_for, it takes an endpoint with optional keyword
arguments for the rule, and returns a generated URL. For example:

{{ url_for('tag/list', tag_name='python') }}

Which might correspond to the url rule:

'/tag/<string:tag_name>'

Incidentally, you can use this function just as well in normal Python code:

from glashammer.utils import url_for


Ali

Italo Maia

unread,
May 9, 2009, 4:37:03 PM5/9/09
to glashammer
Thanks =D
Reply all
Reply to author
Forward
0 new messages