-2

max_heightが無効な構文エラーを生成するのはなぜですか?

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>

編集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))
4

1 に答える 1

1

この行:

{% if person.filter("height <", max_height %)

次のようになります。

{% if person.filter("height <", max_height) %}

また、テンプレート自体でこのようなフィルタリングロジックを使用しないことをお勧めします。そのコードをアプリケーションコードに入れ、テンプレートを使用してHTMLをレンダリングします。

于 2013-03-21T01:52:24.580 に答える