当我上传新文件时,它会保存到应用程序根文件夹,即使我指定了不同的UPLOAD_FOLDER
。为什么配置不起作用?
views.py
:
from flask import render_template
from flask import request, redirect, url_for,flash
from werkzeug.utils import secure_filename
from app import app
import os
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
UPLOAD_FOLD = '/Users/blabla/Desktop/kenetelli/htmlfi'
UPLOAD_FOLDER = os.path.join(APP_ROOT, UPLOAD_FOLD)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/')
def tmrf():
return render_template('main.html')
@app.route('/uploader', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
f.save(secure_filename(f.filename))
return 'file uploaded successfully'
__init__.py
:
from flask import Flask
UPLOAD_FOLDER = ''
ALLOWED_EXTENSIONS = set('*.doc')
app = Flask(__name__)
app.config.from_object('config')
from app import views