为什么我不能让使用谷歌应用程序引擎

问题描述:

数据形式Model.all()这是我在main.py为什么我不能让使用谷歌应用程序引擎

class marker_data(db.Model): 
    geo_pt = db.GeoPtProperty() 
class HomePage(BaseRequestHandler): 
    def get(self): 
     a=marker_data() 
     a.geo_pt=db.GeoPt(-34.397, 150.644) 
     a.put() 
     datas=marker_data.all() 
     self.render_template('3.1.html',{'datas':datas}) 

,并在HTML代码:

{% for i in datas %} 
     console.log(i) 
    {% endfor %} 

但错误是:

i is not defined 

所以我能做什么?

感谢

“我”是由服务器端模板引擎解释,所以你需要:

{% for i in datas %} 
    console.log({{ i }}); 
{% endfor %} 

除了语法错误sje397提到的。所有()方法返回一个Query对象,我认为您需要调用.fetch(n)或.get()来检索实际的marker_data对象。

datas=marker_data.all().fetch(100) 
+1

'Query'对象是可迭代的,并自动调用'取()'你(在20批次,我认为),当他们被遍历幕后:http://code.google.com /appengine/docs/python/datastore/queryclass.html – Cameron 2010-09-16 03:53:51

+0

哦,很高兴知道 - 谢谢! – 2010-09-16 04:06:01