-1
为什么MAX_HEIGHT产生一个无效的语法错误?无效的语法Jinja2的模板值
main.py
max_height = 70
template_values = {
'max_height': max_height # syntax error
...
}
的index.html
<html>
<body>
{% for person in people %}
{% if person.filter("height <", max_height %)
<b>{{ person.first_name }}</b>
<b>{{ person.last_name }}</b>
<b>{{ person.city }}</b>
<b>{{ person.birth_year }}</b>
<b>{{ person.height }}</b>
<hr></hr>
{% endif %}
{% endfor %}
</body>
</html>
EDIT 1 下面是从main.py类的MainPage:
class MainPage(webapp2.RequestHandler):
def get(self):
people_query = Person.all()
people = people_query.fetch(10)
max_height = 70
template_values = {
'people': people
'max_height': max_height
}
template = jinja_environment.get_template('index.html')
self.response.out.write(template.render(template_values))
+1谢谢搅拌机。我修复了代码。我仍然遇到同样的错误:'max_height':max_height。是不是模板值不允许我传递这样的变量? – Anthony 2013-03-21 02:02:39
@Anthony:什么是错误? – Blender 2013-03-21 02:04:26
错误是...第20行'max_height':max_height。 SyntaxError:无效的语法 – Anthony 2013-03-21 02:07:01