【发布时间】:2022-02-11 07:08:11
【问题描述】:
我正在尝试根据来自 HTML 表单的用户输入创建动态 URL。
例如,如果用户输入“AAPL”或“KO”,则下一页应为: webapp.com/result/AAPL 或 webapp.com/result/KO
index.html:
<div class="cell" id="cell-1-2">
<span class="data" style="text-align: center;">
<form action="{{ url_for('ticker_result', variable='variable') }}" method="POST">
<input type="text" name="variable" placeholder="search ticker or company" maxlength="4"
font-size="24px" style="text-transform:uppercase">
<input class="button" type="submit" value="Search" onclick="tickerSymbol();">
</form>
</span>
</div>
我尝试将“变量”部分重命名为几个不同的东西,但没有任何效果,所以我只是停留在这一点上。
main.py:
# Routing to the homepage
@app.route("/")
def markert_hours_today():
return render_template(
"index.html")
# Routing to the result page
@app.route("/result/<variable>", methods = ["GET", "POST"])
def ticker_result(variable):
if request.method == "POST":
result = request.form["variable"]
return render_template(
"result.html",
result=result)
当我运行本地环境并输入股票代码时,下一个 URL 是: webapp.com/result/variable
我假设我需要编辑的是 HTML?我已经阅读了 Flask 的快速入门文档,这对我来说没有意义,并查找了类似的问题,但我似乎无法找到答案。
【问题讨论】: