【发布时间】:2017-04-30 22:23:28
【问题描述】:
我是烧瓶、HTML、Jinja 的新手,我在将值从一个模板传递到另一个模板时遇到了麻烦。我查看了关于 SO 的许多其他页面,但没有人遇到完全相同的问题。我有一个带有下拉选择菜单和提交按钮的页面,一旦用户做出选择,它就会重定向用户。我的问题是我不知道如何将该选择传递给下一页的表单。以下是我的 HTML 表单代码:
<form method="POST" action="search">
<div class="form-group" align="center">
<select class="vertical-menu">
{% for friend in strFriendList %}
<option name="friendToPay" value="{{ friend }}">{{ friend }}</option>
{% endfor %}
</select>
<a href="{{ url_for('payment') }}" class="btn-primary"> Submit</a>
</div>
</form>
以下是我的搜索和支付功能:
@app.route("/search")
def search():
if "email" not in session:
return redirect(url_for("login"))
else:
friendslist1 = Friendship.query.filter_by(username=session["username"]).all()
friendslist2 = Friendship.query.filter_by(friendUserName=session["username"])
strFriendList = [""]
for friend in friendslist1:
strFriendList.append(friend.friendUserName)
for friend in friendslist2:
strFriendList.append(str(friend.username))
form = SelectFriendForm()
return render_template("search.html",strFriendList=strFriendList,form=form)
@app.route("/payment",methods=['GET', 'POST'])
def payment(personToPay):
form = PaymentForm()
if request.method == "POST":
if form.validate() == False:
return render_template("payment.html", form=form)
else:
return render_template("search.html")
# else:
# # Query the database and deposit the amount and subtract from giver
return render_template("payment.html")
我想让在搜索功能中选择的朋友发送到支付功能。任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: python html flask parameter-passing