我目前正在使用 Flask,我想要一个“提交”按钮,一旦按下按钮,就会将表单中的数据 POST 到 Python。
我的文本框如下所示:
<form method="POST"> <style>
textarea {
width: 100%;
height: 200px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
font-size: 16px;
resize: none;
}
</style>
Run Code Online (Sandbox Code Playgroud)
我的按钮看起来像这样:
<button type="submit"></button>
Run Code Online (Sandbox Code Playgroud)
我的 run.py 看起来像这样:
@app.route('/', methods=["POST"])
def some_function():
// do stuff
Run Code Online (Sandbox Code Playgroud)
编辑:我无法让 POST 方法工作。按钮出现,即使按下它也没有任何反应。
您已经有了答案,但对于稍后会阅读此问题的其他人来说,并且因为您粘贴的代码中有很多错误,所以不会使其对其他人有用:
您应该将其放置button在表单内,因此您的表单将如下所示:
<style>
textarea {
width: 100%;
height: 200px;
padding: 12px 20px;
box-sizing: border-box;
border: 2px solid #ccc;
border-radius: 4px;
background-color: #f8f8f8;
font-size: 16px;
resize: none;
}
</style>
<form method="POST">
<textarea name="textbox"></textarea>
<button type="submit" name="submit">Submit</button>
</form>Run Code Online (Sandbox Code Playgroud)
所以你有 atextarea和 abutton来发送表格。
现在,在你的run.py:
@app.route('/', methods=["POST"])
def some_function():
text = request.form.get('textbox')
Run Code Online (Sandbox Code Playgroud)
现在,您可以随心所欲地发短信。
| 归档时间: |
|
| 查看次数: |
7310 次 |
| 最近记录: |