我有,我用它来计算笛卡尔乘积几个列表:在Flask中,如何将python列表打印到Jinja模板?
python.py:
@app.route('/output', methods = ['GET','POST'])
def output():
a = ['one','two']
b = ['three','four']
c = ['five']
d = ['six','seven','eight']
e = ['nine','ten','eleven']
cpl = list(itertools.product(a,b,c,d,e))
return render_template('output.html',cpl = cpl)
output.html:
{% for cp in cpl %}
<p>{{ cp }} </p>
{% endfor %}
不过,我在返回黑屏。
当我在Jupyter中运行相同的python代码时,我得到了返回的列表。
我在哪里可能遇到问题?
这可能只是与您当前的设置有关的问题。我在本地运行您的代码,并获得了预期的输出结果。 –