[stringtemplate-interest] Multimethods
Roman Odaisky
roma at qwertty.com
Fri Nov 14 06:17:21 PST 2008
Hi,
> your template could be
>
> blog_post(m,d,y) ::= "/y/m/d&sessionid=<session.ID>"
> or whatever the field of the session is. would that work?
That would work. But that would cause unnecessary duplication.
Django has a thing called URLconf[1] which allows one to bind URLs to
functions by means of regular expressions. Moreover, it allows one to
determine a URL that would cause a given function to get called with given
arguments.
For example, if a URLconf entry looks like this:
(r"^/(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)$", posts_by_date)
then Django would call posts_by_date(request, year=2008, month=11, day=14).
And when one calls reverse(posts_by_date, year=2008, month=11, day=14), one
gets "/2008/11/14". So one line in a configuration file works both ways. If I
were to create a template like the one you suggested above, it would
duplicate the information that is already known to the application.
I need to have an option to use that system. Adding a get_absolute_url method
to objects works as long as the URL depends only on one object, but recently
I’ve encountered URLs that need more than one. At the moment I’m using hacks
like $o1.url_for_o2.(o2.id)$ where get_url_for_o2() returns an object with
operator [] overloaded.
Do you have anything against explicit adding of templates that call functions
like I proposed in the first message?
References:
[1] http://docs.djangoproject.com/en/dev/intro/tutorial03/#design-your-urls
--
WBR
Roman.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2286 bytes
Desc: not available
Url : http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20081114/50c51cbd/attachment.bin
More information about the stringtemplate-interest
mailing list