0

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

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>
4

1 回答 1

1

Adding fetch() fixed the problem:

class Search(webapp.RequestHandler):
    def post(self):
        query = Pet.all()
        q = query.filter('name =', self.request.get('searchquery')).fetch(10)
于 2010-10-16T22:15:39.833 回答