【发布时间】:2018-04-06 18:44:12
【问题描述】:
我知道这个问题已经被问过很多次了,但是这些答案对我没有帮助,请原谅我再次问。
我在 index.html 页面中获取数据并在下一个 html 页面 (annodisplay.html) 中呈现以供用户查看,然后再单击提交。 我希望仅在用户按下提交按钮后才将数据传递给 python 变量。但我没有在 python 变量中获取表单值。
这是我的 python 烧瓶代码。
app = Flask(__name__)
@app.route('/send', methods=['GET', 'POST'])
def send():
if request.method == 'POST':
affflash = request.form['affflash']
return render_template('annodisplay.html', affflash=affflash)
return render_template('index.html')
@app.route('/get', methods=['GET', 'POST'])
def get():
if request.method == 'POST':
return render_template('submit.html')
return render_template('annodisplay.html')
affflash = request.form['affflash']
print affflash
if __name__ == "__main__":
app.run(debug=True)
这是我的 HTML index.html 代码
<form method="POST" action="/send">
<table class="tg">
<tr>
<td class="tg-031e">AFF_FLASH</td>
<td class="tg-031e">
<select id="AFF_FLASH" name="affflash">
<option selected value="">Select</option>
<option value="Yes">YES</option>
<option value="No">NO</option>
</select>
</td>
</tr>
</table>
<input class="btn btn-primary" type="submit" value="Submit">
</form>
这是我的 annodisplay.html 代码
<form action="{{ url_for('get') }}" method="POST">
<body>
<table class="tg">
<tr>
<td class="tg-bh7e">AFF Flash</td>
<td class="tg-yw4l">{{ affflash }}</td>
</tr>
</table>
<input class="btn btn-primary" type="submit" value="Submit">
</body>
</form>
【问题讨论】:
-
你能运行那个 Flask 应用程序吗?由于我看不到任何像
@app.route('/') @app.route('/index') def index():这样的根路由,我怎样才能到达那个 index.html ? -
是的,我可以。函数 send 对 index.html 有返回响应。 return render_template('index.html')"