【发布时间】:2022-01-09 02:04:12
【问题描述】:
from flask import Flask, render_template,request
app = Flask(__name__)
@app.route('/',methods=['post'])
def main():
if (request.method=="POST"):
text=request.form('write')
if(text==None):
text=""
else:
text=""
return render_template('form.html',text=text)
if __name__ == "__main__":
app.run(debug=True)
我只想接收 POST 方法。所以我将method 选项设置为methods=["post"]。但它总是发送HTTP 405 Not Allowed Method 错误。
<html>
<head>
<title>Using Tag</title>
</head>
<body>
<form method="POST">
<input type="text" name="write">
<input type="submit">
</form>
{{ text }}
</body>
</html>
我想知道为什么这个应用程序只发送 HTTP 405 响应。
【问题讨论】:
-
你的方法应该包括
GET和POST。
标签: python flask http-status-code-405