我一直在研究烧瓶中的一个项目,我被困在需要弄清楚如何产生一个烧瓶模板而不是另一个的部分上。
例如,为了说明我的意思,我有一个这样的程序。
主文件
from flask import Flask, stream_with_context, Response, render_template
app = Flask('app')
@app.route('/')
def hello_world():
def generate():
yield render_template('index.html')
yield render_template('index2.html')
return Response(stream_with_context(generate()))
app.run(host='0.0.0.0', port=8080)
Run Code Online (Sandbox Code Playgroud)
索引.html
<h3>Hi</h3>
Run Code Online (Sandbox Code Playgroud)
索引2.html
<h3>Bye</h3>
Run Code Online (Sandbox Code Playgroud)
运行 main.py 返回:
Hi
Bye
Run Code Online (Sandbox Code Playgroud)
尽管这是有道理的,但我的目标是使其结果恰好Bye取代Hi. 我尝试了其他路径,例如返回两者,但都没有奏效。关于我如何做到这一点的任何想法?