Doc for add check upload file

This commit is contained in:
Wing 2014-05-17 14:44:34 +08:00
parent da1c1f0d7f
commit 02b02543b3

View file

@ -56,7 +56,16 @@ the file and redirects the user to the URL for the uploaded file::
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
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)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))