I'm learning python (Flask) I've tried to upload file by flask but it show an error
> PermissionError: [Errno 13] Permission denied: 'C:\Users\Muhammad Usama Javed\Desktop\autotech\static\upload_files'
Here's my code
@app.route('/upload_files', methods=['GET', 'POST'])
def upload_files():
if request.method == 'POST':
if request.files:
# fn.fun_upload_files(request.files['img'])
img = request.files['img']
filename = img.filename
img.save(os.path.join("C:\\Users\\Muhammad Usama Javed\\Desktop\\autotech\\static\\upload_files"), filename)
return redirect('/admin/files')
You may not have configured the application. Try adding this value:
import os
from flask import Flask, flash, request, redirect, url_for
from werkzeug.utils import secure_filename
# The path where the files will be saved
UPLOAD_FOLDER = '/path/to/the/uploads'
ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'}
app = Flask(__name__)
# Add a new value in the config application
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.