Am 26.02.2011 11:36 schrieb Diez B. Roggisch:
@expose('honutv.templates.index')
def get_shinfo(self):
result = rdshinfo()
return result

That should work, but the expose decorator must have the same
identation as the def statement.

It does? Under wich name does the result appear in the template
namespace? I was always under the impression for that you need to return
dicts.

Sorry for creating confusion, I hadn't seen that you already answered.

You're right, since rdshinfo() returns a sequence, you need to wrap in into a dict first. Actually rdshinfo() doesn't even return a sequence of model objects, but only a sequence of tuples, so the template needs to look like this:

<ul>
  <li py:for="row in result">
    ${row[0]}, ${row[1]}
 </li>
</ul>

Anyway, it is recommended to set up proper SQLAlchemy Table instance and/or ORM classes, so that you don't need to care about connections and engines when querying the database, i.e. the rdshinfo() is not necessary, you just call DBSession.execute(select([shows])) or DBSession.query(Show), and you can access your columns as attributes. But I think in the former case you need to write row.c.title instead of just row.title.

Usually I also set a session-aware mapper or query object, so I don't even need the DBSession and can just write Show.query to get an iterator over all Show objects. The model quickstart template already has the necessary code, you just need to comment it out.

-- Christoph

--
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en.

Reply via email to