On Tue, 2012-01-03 at 11:23 -0800, Brent Lingle wrote:
> The dictionary provided a little bit more control than a list.
> This solution works, but if there is a way to just do
That doesn't make sense. Lists are lists, dicts are dicts. One is not
better than the other. They just serve completely different purposes.
As far as I can see from your code, you keep overwriting a single dict
once per database row, and you end up having a single row assigned to
the dict instead of one dict per selected row. That's a big waste of
computing time, if you ask me. You should just select one record that
you actually need, and use that.
Anyway, that is not at all what I suggested, and it doesn't look like a
valid solution to your _original_ question.
> def bio():
> return db.select('bio')
Yes, you can certainly keep that. But you cannot use it like this:
> $for b in bio:
You have to call bio inside your template, not when assigning to the
global. If you assign the return value of bio() to the global, you can
only iterate it once unless you convert it into a regular list. If you
want to iterate the results each time you render the page, you need to
call it from the template.
So your code should be:
$for b in bio():
instead of
$for b in bio:
Of course, this means the database will be hit each time you render this
page, which, depending on how much data you have in the db, how many
users visit the page, and other factors, may become too much.
That's why converting it to a list, which can be iterated multiple
times, is a much better solution.
--
Branko Vukelic <[email protected]>
--
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.