Jinja variables within the Flask url_for function [duplicate]

点点圈 提交于 2019-12-04 18:24:56

问题


I have tried multiple different things, but cannot get the URL to appear as /item like I want it to. I know that everything else is functioning correctly because if I simply replace {{item}} with a string, it works fine. Am I missing something here?

Here is the code section where the problem lies:

<div class="person_images_group">
    {% for item in names %}
        <div class="personlist">
            <a href={{ url_for('name', name = {{item}} ) }}>
                <img id={{ item }} src="" alt={{ item }} width="40" height="40">
            </a>
        </div>
        <script>
            document.getElementById("{{ item }}").src = getName("{{ item }}");
        </script>
    {% endfor %}
<div>

Thank you


回答1:


You try use {{}} in {{}} block. So right usage is {{ url_for('name', name=item) }}.



来源:https://stackoverflow.com/questions/23988561/jinja-variables-within-the-flask-url-for-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!