【发布时间】:2018-04-17 23:48:00
【问题描述】:
这是我的代码,一个非常简单的程序。即使 POST 存在,服务器在 POST 请求时仍显示 405。我试过邮递员,http-prompt,但结果是一样的“405”。在向服务器发送 OPTIONS 请求时,只有 GET、HEAD 和 OPTIONS 显示为允许的方法。即使通过 html 表单的 POST 请求也显示 405,当然因为服务器没有尽管 methods kwarg 中存在 POST,但甚至将 POST 作为允许的方法。
- 我在 Mac 机器上(High Sierra)
- 尝试使用 gunicorn 和 inbuilt 烧瓶服务器。
- 尝试使用 Postman、http-prompt
@app.route('/')
def index(methods=['GET', 'POST']):
if request.method == 'GET':
return render_template('index.html')
else:
return 'POST'
index.html 包含一个简单的 HTML 标题。
【问题讨论】: