Hi,

The homepage of my app displays a list of items with their content
(might as well think of it as a blog), and you can also link to
individual items. I'd like to use the same set of templates for both
cases.

So my handlers look something like this:
-----------------------------------------------------
class MainPage(webapp.RequestHandler):
    def get(self):
        items = db.GqlQuery('SELECT * FROM Item')
        values = {'items': items}
        self.response.out.write(template.render('main.html', values))

class SingleItem(webapp.RequestHandler):
    def get(self):
        key = #determine item key
        linked_item = db.get(key)
        values = {'linked_item': linked_item}
        self.response.out.write(template.render('main.html', values))
-----------------------------------------------------

And here's main.html:
-----------------------------------------------------
{% if linked_item %}
    {{ linked_item.content }}
{% else %}
{% for item in items %}
    {{ item.content }}
{% endfor %}
{% endif %}
-----------------------------------------------------

This doesn't look like a great solution but I haven't been able to
think of (or find) a better one. I've been told to use db.get when
possible because it's faster, but the object it returns isn't iterable
and so the template becomes awkward.

Is there a way to put the return from db.get into an iterable object?
That way I could simply have "{% for item in items %}
{{ item.content }} {% endfor %}" in my template and it would work
without errors.

Should I just use a query instead of db.get? Any other solutions? I've
been looking through GAE and Django template docs but haven't found
anything yet.

Any ideas, even a link to the right piece of documentation would be
awesome.

Thanks,
Kev

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" 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/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to