The problem is that only Input_1()
will run, for the /
route.
The solution is to use one route and one function:
from flask import Flask
from flask import render_template
from flask import request
# ^^^ prefer one import per line
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
name1 = request.form.get('name1', '0')
name2 = request.form.get('name2', '0')
return render_template('index.html',
DataFromPython1=name1,
DataFromPython2=name2)
else:
return render_template('index.html')
if __name__ == '__main__':
app.run()
If its a POST
request, then retrieve all the values you want from the form
, and pass them to be rendered.
Most likely, if its a GET
request you want to just load index.html
, so I've added that in as well.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…