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.
JavaScript
x
20
20
1
@app.route('/', methods = ['POST'])
2
def index():
3
if 'file' not in request.files:
4
return redirect(request.url)
5
file = request.files['file']
6
# if user does not select file, browser also
7
# submit a empty part without filename
8
if file.filename == '':
9
flash('No selected file')
10
return redirect(request.url)
11
if file and allowed_file(file.filename):
12
filename = secure_filename(file.filename)
13
warped = transform_file(file)
14
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
15
16
17
18
if __name__ == '__main__':
19
app.run(host='127.0.0.1', threaded=True)
20
Advertisement
Answer
you are trying to have only a root i.e “/” in your route.
Can you try with a site, something like below:
JavaScript
1
2
1
@app.route('/', methods=['GET', 'POST'])
2