-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
36 lines (27 loc) · 911 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
This Module for contains the route for uploading a file and resturning the same
file data back in the response once stored.
"""
import os
from flask import (Flask, render_template, request)
from werkzeug.utils import secure_filename
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = os.path.join(app.root_path, 'static', 'img')
@app.route("/", methods=['POST'])
def upload():
"""
This route saves the file uploaded in the form and returns the same file
in the response.
"""
file = request.files['file']
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return render_template('home.html', filename=filename)
@app.route("/", methods=['GET'])
def home():
"""
This route renders the HTML page to show basic form for file upload.
"""
return render_template('home.html')
if __name__ == '__main__':
app.run(port=5050, host='0.0.0.0')