【问题标题】:Search form in Google App Engine with Mako Template使用 Mako 模板在 Google App Engine 中搜索表单
【发布时间】:2010-10-16 21:20:29
【问题描述】:

脚本在 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>

【问题讨论】:

    标签: google-cloud-datastore mako


    【解决方案1】:

    添加 fetch() 解决了问题:

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

    【讨论】:

      猜你喜欢
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 2011-03-08
      • 2012-06-14
      • 1970-01-01
      • 2014-07-14
      • 1970-01-01
      相关资源
      最近更新 更多