-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpload.py
More file actions
27 lines (23 loc) · 966 Bytes
/
Copy pathUpload.py
File metadata and controls
27 lines (23 loc) · 966 Bytes
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
from flask import Flask, render_template
from flask import FlaskForm
from wtforms import FileField, SubmitField
from werkzeug.utils import secure_filename
import os
from wtforms.validators import InputRequired
app = Flask(__name__)
app.config['SECRET_KEY'] = 'supersecretkey'
app.config['UPLOAD_FOLDER'] = 'static/files'
class UploadFileForm(FlaskForm):
file = FileField("File", validators=[InputRequired()])
submit = SubmitField("Upload File")
@app.route('/', methods=['GET',"POST"])
@app.route('/home', methods=['GET',"POST"])
def home():
form = UploadFileForm()
if form.validate_on_submit():
file = form.file.data # First grab the file
file.save(os.path.join(os.path.abspath(os.path.dirname(__file__)),app.config['UPLOAD_FOLDER'],secure_filename(file.filename))) # Then save the file
return "File has been uploaded."
return render_template('index.html', form=form)
if __name__ == '__main__':
app.run(debug=True)