2010-10-16 66 views
0

脚本位于data.py中,模板文件为search.mako。搜索表单位于MainPage方法中(不包含在下面的代码中)。我输入搜索字词,但没有任何反应。你能帮助理解我做错了什么吗?谢谢。使用Mako模板在Google App Engine中搜索表单

class Pet(db.Model): 
    name = db.StringProperty() 

class Search(webapp.RequestHandler): 
    def post(self): 
     query = Pet.all() 
     results = self.request.get('searchquery') 
     q = query.filter('name =', 'results') 

     template_values = {'q': q,} 

     path = os.path.join(os.path.dirname(__file__), 'search.mako') 
     templ = Template(filename=path) 
     self.response.out.write(templ.render(**template_values)) 

这是search.mako

<html> 
<body> 

% for cat in q: 
    <p>${cat.name}</p> 
% endfor 

</html> 
</body> 

回答

1

添加fetch()方法解决了这一问题:

class Search(webapp.RequestHandler): 
    def post(self): 
     query = Pet.all() 
     q = query.filter('name =', self.request.get('searchquery')).fetch(10) 
相关问题