Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.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 缩短施工时间_Python_Jinja2 - Fatal编程技术网

Python 缩短施工时间

Python 缩短施工时间,python,jinja2,Python,Jinja2,挑战在于减少代码的构造,如果可能的话,加快代码的处理 {% for tp1 in test.tab_tp1s %} {{ tp1.name }} {% endfor %} {% for tp2 in test.tab_tp2s %} {{ tp2.name }} {% endfor %} {% for tp3 in test.tab_tp3s %} {{ tp3.name }} {% endfor %} 也许,这很难说,因为我们不知道test中存储了什么,我假设test

挑战在于减少代码的构造,如果可能的话,加快代码的处理

{% for tp1 in test.tab_tp1s %}
    {{ tp1.name }}
{% endfor %}
{% for tp2 in test.tab_tp2s %}
    {{ tp2.name }}
{% endfor %}
{% for tp3 in test.tab_tp3s %}
    {{ tp3.name }}
{% endfor %}

也许,这很难说,因为我们不知道test中存储了什么,我假设test是一个包含3个键的字典,每个键都包含一个子键name?

这很模糊。可能需要在删除之前提供尽可能多的详细信息。这是一个有效的代码。我可以用Jinja写同样的东西吗?tab_TP1、tab_TP2和tab_TP3都来自测试,所以只需循环测试即可first@Ajx我建议试试这个(可能很适合那里)。事实上,我们有不止一个“测试”。我们有:test.tab\u tp1s test.tab\u tp2s test.tab\u tp3s每个部分都有不同的数据
{% for tab in test %}
    {% for tp in test[tab]
        {{ tp.name }}
    {% endfor %}
{% endfor %}