【发布时间】:2015-11-24 14:48:21
【问题描述】:
我正在开发一个网络应用程序;添加通过 Ajax 调用的新 Python/Flask 方法后,浏览器控制台出现错误:
“POST 405(不允许的方法)”
我在这里发现了很多类似的问题,但没有答案:
- 我为路由指定了 GET 和 POST 方法:
methods=['GET','POST'] - 我重启了apache
- 我将 dataType 设置为“jsonp”
同一文件中的多个 Python/Flask 函数已经以相同的方式工作,没有问题。也许 Flask 应该重新加载?配置了新路由?
此外,我的机器上的本地服务器一切正常。直到现在我将代码移植到托管服务器时才遇到此问题。
我的 JS
function launchStreaming(jsonPath){
var data = {};
data.file = jsonPath;
$.ajax({
type: 'POST',
url: "/launchStream",
data: JSON.stringify(data),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(data) {
stringDebug('streaming Success!');
},
error: function(e) {
stringDebug(e);
alert ("Problem during streaming, please refresh and retry");
}
});
我的 Python
@app.route('/launchStream', methods=['POST'])
def launchStream():
if request.method == 'POST':
json_datas = request.json
# do streaming...
return json.dumps({'success':True}), 200, {'ContentType':'application/json'}
提前致谢
【问题讨论】:
标签: python ajax apache web flask