gpt4 book ai didi

python - Flask Form将数据发布到另一个html页面

转载 作者:行者123 更新时间:2023-12-01 03:13:44 24 4
gpt4 key购买 nike

我有一个获取数据并重定向到 bk.html 页面的表单。我想从提交的表单中获取结果,并使用该信息进行页面重定向。我可以动态地将其放在同一页面上,但我不知道如何将其添加到新页面。

from flask import Flask, render_template, request, redirect
app = Flask(__name__)
# our index route will handle rendering our form
@app.route('/')
def index():
return render_template("index.html")

@app.route('/users', methods=['POST'])
def create_user():
print "Got Post Info"
name = request.form['name']
DojoLocation = request.form['location']
FavoriteLanguage = request.form['Language']
textarea = request.form['textarea']
# redirects back to the '/' route
return render_template('bk.html')

app.run(debug=True) # run our server
<!DOCTYPE html>
<html>
<head>
<title>Dojo Survey Index</title>
<meta charset="utf-8">
<link rel='stylesheet' type='text/css' href="{{ url_for('static', filename='css/my_style_sheet.css')}}">
<script type="text/javascript" src="{{ url_for('static', filename='js/my_script.js')}}"></script>
</head>
<body>
<div id = container 1 >
<form action='/users' method='post'>
Name: <input type='text' name='name'>
Dojo Location: <select name="location">
<option value="Silicon Valley">Silicon Valley</option>
<option value="Seattle">Seattle</option>
<option value="Los Angeles">Los Angeles</option>
<option value="Dallas">Dallas</option>
<option value="Washington DC">Washington DC</option>
<option value="Dallas">Dallas</option>
<option value="Chicago">Chicago</option>
<option value="Berkely">Berkely</option>
<option value="Orange County">Orange County</option></select>
Favorite Language: <select name="Language">
<option value="ios swift">ios swift</option>
<option value="Ruby on rails">ruby on rails</option>
<option value="Python">Python</option>
<option value="Mean">Mean</option>
<option value="C# ">C# DC</option>
</select>
<textarea name="textarea" value = "textbox" rows="4" cols="50" name="comment" ></textarea>

<input type='submit' value='submit'>
</form>
</div>
</body>
</html>

最佳答案

当你返回render_template()函数时,你可以添加变量:

var1 = 'this is a test string'
return render_template("bk.html", var1 = var1)

在您的 bk.html 文件中,包含以下内容以在您希望显示的位置显示变量。

{{ var1 }}

您可以在 http://jinja.pocoo.org/ 上阅读更多内容

关于python - Flask Form将数据发布到另一个html页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42656751/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com