我是 Flask 的新手,并遵循了这个演练,但遇到了一个问题。我希望用户能够在 index.html 页面上的文本字段中输入文本,点击提交按钮,然后将它们带到 trader.html 页面。当按下按钮时,我在下面的代码中遇到了 404 Page Not Found 错误,但我不确定我哪里出错了?点击按钮后,URL 栏显示正确的 /trader.html 地址,但出现 404 错误页面。
我在 SO 上找到的针对类似问题的 2 个答案在这里不起作用,因为他们提到需要有一个单独的 app.route 才能将它们导航到正确的第二页,但我已经在我的代码中进行了设置???
应用程序.py
from flask import Flask, request, jsonify, render_template
@app.route('/', methods = ['GET'])
def hello():
return render_template('index.html')
@app.route('/trader', methods = ['POST'])
def trader_page():
the_stock=request.form['inputted_stock']
return render_template('trader.html')
索引.html
<h1 style="color: #4485b8;">Welcome to the live stock trader!</h1>
<p>Select a stock ticker below to begin testing:</p>
<form action="/trader.html" method="POST">
<option value="AAPL">AAPL</option>
<option value="ABBV">ABBV</option>
<option value="ABT">ABT</option>
</select><br /><br />
<table>
<tr><td>Enter Stock Ticker</td><td><input type="text" name="inputted_stock" /></td></tr>
</table>
<input type="submit" value="Submit"/></form>
<p></p>
<table class="editorDemoTable" style="vertical-align: top;">
<thead></thead>
</table>
交易者.html
<h1 style="color: #4485b8;">{{inputted_stock}} trader!</h1>
<p>Begin testing...</p>
慕盖茨4494581
相关分类