因此,您的表单代码可能看起来像这样(这只是一个示例):
<form method='POST' action="/"> <p>username: <input type="text" name="username"/></p> <p>password: <input type="password" name='password'/></p> <p><input type="submit" value="Login" /></p> </form>
action =“ …”应该是您要发布到的路径。 因此,如果我们要发布到“ /”路径,则可以执行以下操作,并使用以下命令将其捕获到您的代码中:
@app.route('/', methods=['GET', 'POST'])def hello(): if request.method == 'POST': .... # Add whatever pre you want to execute if it is a post request now = datetime.datetime.now() timeString = now.strftime("%Y-%m-%d %H:%M") templateData = { 'title' : 'HELLO!', 'time': timeString } return render_template('main.html', **templateData)我们需要更改app.route部分,因为我们必须指定我们可以通过Get请求或Post请求到达此路由。我们可以使用 if request.method
==’POST’ 来检查它是否是一个Post请求 :
希望这可以帮助。



