我正在尝试使用flask将我的html表单数据传递给python,但是我不确定100%我哪里出了错
Python
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def index():
return render_template('home.html')
@app.route('/form', methods = ['GET', 'POST'])
def form():
your_name = request.form['your_name']
customer_number = request.form['customer_number']
msg = request.form['msg']
if __name__ == '__main__':
app.run()
这是来自 HTML
的<form action="smssend.py" method="post">
<label for="msg">Message</label>
<textarea id="msg" name="msg" rows="5" cols="50"> </textarea> <br>
<label for="your_name">Your Name:</label>
<input type="text" name="your_name" id="your_name" /> <br>
<label for="customer_number">Customers Number:</label>
<input type="text" name="customer_number" id="customer_number" /> <br>
<input type="submit">
</form>
答案 0 :(得分:1)
您需要将操作更改为处理请求的URL,如下所示:
<form action="http://localhost:8000/form" method="post"> ... </form>
ofc根据您的设置更改URL。