【发布时间】:2019-07-18 07:10:07
【问题描述】:
没有重定向一切正常,但有了这个重定向,似乎没有任何工作。我尝试更新代码,尝试强制 POST 请求,检查大量 SO 帖子,但没有找到适合我的解决方案。
使用 Python 3.7 烧瓶代码:
from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html")
@app.route('/', methods=['POST'])
def num_of_students():
num = request.form['text']
return redirect(url_for('test123',num=num))
@app.route('/test123')
def test123():
return render_template("test.html")
if __name__ == "__main__":
app.run(debug=True)
HTML 代码 索引:
<!doctype html>
<title>Rubric</title>
<label>Welcome to the Autograding Rubric</label>
<p>Please enter the number of students.</p>
<form method="POST">
<input type="text", name="text">
<input type="submit">
</form>
</html>
测试:
<!DOCTYPE html>
<title>Test</title>
<p>Test Var: {{ num }}</p>
【问题讨论】:
标签: html python-3.x flask