app route img methods GET POST def upload_file if request method POST

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
@app.route('/img', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
saved_request = flask.ctx.RequestContext(app, request.environ, request=request).copy()
return jsonify(test = saved_request.args.get('test'), A= str(flask.ctx.RequestContext(app, request.environ, request=request)))
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<input type=submit value=Upload>
</form>
'''