Answer a question

Here is my code

    <div class="form-group">
        {{ form.target_price.label }}
        {% if price %}
            {{ form.target_price(class="form-control", placeholder='{{ price }}') }}
        {% else %}
            {{ form.target_price(class="form-control") }}
        {% endif %}
    </div>`

When there is a price it should pass in the price as placeholder of the form. But what it does is it pass '{{ price }}' as a string. Any idea why ?

Answers

Between double braces you are outside the scope of Jinja2 processing, and into the scope of python processing. In Python the '{{ price }}' text is a string, which will be printed.

To get what you want (the string for the price) use str(price), no quotes or braces; WTForms is smart enough to render in the double quotes required by HTML.

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐