On Mon, 2012-01-02 at 18:51 -0800, Brent Lingle wrote:
> def bio():
>     bio = db.select('bio')
>     return bio
> 
> then assigned it to templates,
> 
> web.template.Template.globals['bio'] = bio()

Try it this way:

def bio():
  return db.select('bio')

web.template.Template.globals['bio'] = bio

And then:

$for b in bio():
   ...

Alternatively convert the results into a list and use it as a list:

web.template.Template.globals['bio'] = [b for b in db.select('bio')]

$for b in bio:
   ...

Second method (if it works at all) should be faster because it only hits
the database once, but you will need to reload/reassign the list every
time a new bio is entered into the database.

I suggest this because, iirc, web.py uses a custom iterable, that can
only be iterated once. After that, it is exhausted and you cannot
iterated again. The way you've set it up, you'd only get to iterate it
once per all requests until the app is restarted.

Of course, it's been a long while since I used web.py so I might be
wrong.


-- 
Branko Vukelic <bra...@brankovukelic.com>


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

Reply via email to