Browse Source

Merge pull request #1062 from SteelyWing/patch-2

Doc for add check upload file
pull/1077/head
Kenneth Reitz 11 years ago
parent
commit
16a7dd06aa
  1. 9
      docs/patterns/fileuploads.rst

9
docs/patterns/fileuploads.rst

@ -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))

Loading…
Cancel
Save