【发布时间】:2020-12-16 19:09:20
【问题描述】:
App.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="." method="post">
Search: <input type="text" name="search">
<input type="submit" value="Show">
</form>
</body>
</html>
main.py
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/CmpPr')
def cmpP():
return render_template('CmpPr.html')
@app.route('/CmpSpes')
def cmpS():
return render_template('CmpSpes.html')
@app.route('/App', methods=['POST', 'GET'])
def App():
search = request.form['search']
return render_template('output.html', n=search)
@app.route('/Gro')
def Gro():
return render_template('Gro.html')
if __name__ == '__main__':
app.run(debug=True)
我已经创建了多个 html 页面
我想打印消息,从 TextBox(上面的代码)请求并打印到另一个 html 页面
我尝试使用 request.form.get('search') 但它返回 null
如果我使用 request.form.get('search', FALSE or TRUE) 它返回 FALSE 或 TRUE
我也使用 if else 循环来指定 GET 和 POST 方法,仍然显示相同的错误
谁能帮我解决这个问题
谢谢
【问题讨论】:
-
看起来
<form action="."应该是<form action="/App" -
谢谢先生,我也试过了,但是没用。