[FIXED] How to pass variable in url_for flask?

Issue

in place of newyork I want to pass form.city.data which is a input from form by the user.

    <div>
        <iframe height="800" width="100%" class="p-5 embed-responsive-item"
            src="{{ url_for('static',filename='videos/newyork.html') }}" allowfullscreen></iframe>
    </div>

Solution

u can try this way

{% set path = url_for('static',filename='videos/' + form.city.data + '.html') %}
<div>
    <iframe height="800" width="100%" class="p-5 embed-responsive-item"
        src="{{ path }}" allowfullscreen>
    </iframe>
</div>

Answered By – Dương Thái

Answer Checked By – Pedro (Easybugfix Volunteer)

Leave a Reply

(*) Required, Your email will not be published