首页 > 解决方案 > 尝试通过 localhost 连接到烧瓶时出错

问题描述

我可以在 github 上使用烧瓶发送 Post 请求的脚本。

我正在尝试运行脚本以在本地主机上建立连接。但我得到以下回复

The method is not allowed for the requested URL.

@app.route('/', methods = ['POST'])
def index():
    if 'file' not in request.files:
        return redirect(request.url)
    file = request.files['file']
    # if user does not select file, browser also
    # submit a empty part without filename
    if file.filename == '':
        flash('No selected file')
        return redirect(request.url)
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        warped = transform_file(file)
        return send_from_directory(app.config['UPLOAD_FOLDER'], filename)



if __name__ == '__main__':
    app.run(host='127.0.0.1', threaded=True)

标签: pythonflask

解决方案


你试图在你的路线中只有一个根,即“/”。

你可以尝试一个网站,如下所示:

@app.route('/', methods=['GET', 'POST'])

推荐阅读