我正在学习python(Flask),我试着按Flask上传文件,但它显示了一个错误
这是我的密码
@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')
您可以在图片中看到的错误
您可能尚未配置应用程序。尝试添加此值:
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
来源