在Flas中打印HTML页面上的python控制台输出

2024-04-26 04:02:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在Flask中打印Html页面上的python控制台输出。请有人帮我做同样的事。我做了三份档案。应用程序副本, 索引.html以及结果.html. 在

我的应用程序副本公司名称:

for i in image_path_list:
        j=j+1
        if i in duplicate:
            continue
        else:
            print(i+"  "+str(count[j])+"\n")
    return render_template('results.html', file_urls=file_urls)

if __name__ == '__main__':
    app.run()

这是我的结果.html在

^{pr2}$

Tags: inimage名称应用程序flaskforifhtml
1条回答
网友
1楼 · 发布于 2024-04-26 04:02:31

1)count不是python函数。而是使用enumerate。在

2)在嵌套迭代中使用变量i,这意味着第二个变量将覆盖最外层的值,这将中断迭代。在

你可以这样做:

file_urls = []
for count, image_path in enumerate(image_path_list):
   if image_path not in duplicate:
      file_urls.append(str(count) + ". " + image_oath)

return render_template('results.html', file_urls=file_urls)

或者:

^{pr2}$

甚至:

return render_template('results.html', file_urls=[".".join(str(count),image_path) for count, image_path in enumerate(image_path_list) if image_path not in duplicate])

不过,我建议使用第一个,因为它更具可读性。在

关键是,Python确实比C简单,你很快就会习惯它:)

相关问题 更多 >