Skip to content
Advertisement

Error when trying to connect to flask via localhost

I can across a script on github that send a Post request using flask.

I am trying run the script to establish a connection on my local host. But I get the below response

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)

Advertisement

Answer

you are trying to have only a root i.e “/” in your route.

Can you try with a site, something like below:

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

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement