You need to fetch() your entities, you cannot just pass the query
object to the template.
Also, template.render() expects a dictionary as its second argument.
Try this code:
def get(self):
query = db.GqlQuery("SELECT * FROM Lists ORDER BY date")
lists = query.fetch(10)
path = os.path.join(os.path.dirname(__file__), 'main.html')
self.response.out.write(template.render(path, {'lists': lists}))
In your template you can iterate over the 'lists' variable.
Cheers,
Alex
--
www.muspy.com
On Dec 28, 1:11 pm, Pikaurd Chen <[email protected]> wrote:
> There is my code. Thx
> # --> model define
> class Lists(db.Model):
> type = db.IntegerProperty()
> money = db.IntegerProperty()
> remark = db.StringProperty(multiline=True)
> date = db.DateTimeProperty(auto_now_add=True)
>
> #TestHandler define
> class TestHandler(webapp.RequestHandler):
>
> def get(self):
> #try:
> lists_query = db.GqlQuery("SELECT * FROM Lists ORDER BY date
> LIMIT 10")
> #except:
> # logging.error("Datastore query error")
>
> path = os.path.join(os.path.dirname(__file__), 'main.html')
> self.response.out.write(template.render(path, lists_query))
>
> On Dec 28, 2008, at 7:46 AM, Alexander Kojevnikov wrote:
>
>
>
> > Could you post here your code (both the querying part and the model
> > definition)?
>
> > On Dec 28, 2:59 am, Pikaurd <[email protected]> wrote:
> >> Hi guys. I got a error "AttributeError: 'GqlQuery' object has no
> >> attribute 'has_key'" when I executing the GQL and my statement is
> >> "SELECT * FROM Lists ORDER BY date LIMIT 10".
> >> At first I think the statement have some problem then I changed to
> >> <kind>.all() but the same error.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---