I have been working on a project in flask and I am stuck on one part where I need to figure out how to yield one flask template over another.
To illustrate what I mean, for example, I have a program like this.
main.py
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)
index.html
<h3>Hi</h3>
index2.html
<h3>Bye</h3>
Running main.py returns:
Hi
Bye
Even though this makes sense, my goal is to make it result in just Bye
which should replace Hi
. I tried other paths like returning both but none of them worked. Any ideas on how I can do this?