开发者

Search form in Google App Engine with Mako Template

开发者 https://www.devze.com 2023-01-20 02:07 出处:网络
The script is in data.py and template file is search.mako. The search form is in MainPage method (not included in the code below). I enter the search term but nothing happens. Can you help understand

The script is in data.py and template file is search.mako. The search form is in MainPage method (not included in the code below). I enter the search term but nothing happens. Can you help understand what I am doing wrong? Thank you.

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

And this is the search.mako

<html>
<body>

% for cat in q:
  <p>${cat.name}<开发者_如何学JAVA;/p>
% endfor  

</html>
</body>


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消