Search form in Google App Engine with Mako Template
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)
精彩评论