On Thu, Jun 24, 2010 at 10:26 PM, Joshua Bronson <[email protected]> wrote:
> On Mar 30 2009, 10:52 am, Michael Glaesemann
> <[email protected]> wrote:
>>
>> Hi!
>>
>> I'm trying out web.py. When writing templates, I'd rather not hard-
>> code URIs for form action or anchor href attributes: I'd like to be
>> able to use functionality similar to link_to in Pylons and Rails. Is
>> there a common (or maybe uncommon?) way of doing this?
>>
>> Michael Glaesemann
>> [email protected]
>
> I had the same question. Can anyone help?

Since web.py has no model layer, that functionality would make no
sense. On the other hand, web.py's template system can use methods you
pass it as arguments, or as globals, so you can write a method that
evaluates to an URL with arguments you pass it, and use that in the
template.

def link_to(title):
    return '/base/url/%s' % urlize(title)

Another strategy I've used is to attach the pre-generated URL to the
storage object that contains the database record you use in your
template.

records = db.select(...)
new_records = []
for record in records
    record.url = '/base/url/%s' % urlize(record.title)
    new_records.append(record)



-- 
Branko Vukelić

[email protected]
[email protected]

Check out my blog: http://www.brankovukelic.com/
Check out my portfolio: http://www.flickr.com/photos/foxbunny/
Registered Linux user #438078 (http://counter.li.org/)
I hang out on identi.ca: http://identi.ca/foxbunny

Gimp Brushmakers Guild
http://bit.ly/gbg-group

-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to