Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 正在学习使用Jinja2模板,缺少URL值_Python_Html_Jinja2 - Fatal编程技术网

Python 正在学习使用Jinja2模板,缺少URL值

Python 正在学习使用Jinja2模板,缺少URL值,python,html,jinja2,Python,Html,Jinja2,我正在学习如何使用Jinja2模板(参见下面的代码)。当我向表单中添加一个项目时,我希望url会变成这样 http://localhost:8080/?food=steak&food=eggs&food=cheese 然而,最终的结果是,第一个食物将有一个值,但其他所有内容都将为空。它看起来像这样: http://localhost:8080/?food=asd&food=&food= 我做错了什么 <form> <h2>Add

我正在学习如何使用Jinja2模板(参见下面的代码)。当我向表单中添加一个项目时,我希望url会变成这样

http://localhost:8080/?food=steak&food=eggs&food=cheese
然而,最终的结果是,第一个
食物将有一个值,但其他所有内容都将为空。它看起来像这样:

http://localhost:8080/?food=asd&food=&food=
我做错了什么

<form>
    <h2>Add a Food</h2>
    <input type="text" name="food">
    {% if items %}
        {% for items in items %}
            <input type="hidden" name="food" value="{{item}}">
        {% endfor %}
    {% endif %}

    <button>Add</button>

    {% if items %}
        <br>
        <br>

        <h2>Shopping List</h2>
        <ul>
            {% for item in items %}
                <li>{{ item }}</li>
            {% endfor %}
        </ul>
    {% endif %}
 </form>

我不确定,但我认为问题在于你的
标签。尝试类似于
的方法。我觉得你现在的按钮没什么用


我不确定,但我认为问题在于你的
标签。尝试类似于
的方法。我觉得你现在的按钮没什么用


对于项目中的项目

    {% for item in items %}
        <input type="hidden" name="food" value="{{item}}">
    {% endfor %}
{items%]中的项的%
{%endfor%}

用于项目中的项目

    {% for item in items %}
        <input type="hidden" name="food" value="{{item}}">
    {% endfor %}
{items%]中的项的%
{%endfor%}

hmm…尝试过但没有改变消失值的问题hmm…尝试过但没有改变消失值的问题ah,我不敢相信我错过了。我已经盯着这个看了20分钟了。接得好。啊,真不敢相信我错过了。我已经盯着这个看了20分钟了。抢手货