本文整理汇总了Python中flask.app.Flask.config['UPLOAD_DIRECTORY']方法的典型用法代码示例。如果您正苦于以下问题:Python Flask.config['UPLOAD_DIRECTORY']方法的具体用法?Python Flask.config['UPLOAD_DIRECTORY']怎么用?Python Flask.config['UPLOAD_DIRECTORY']使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.app.Flask
的用法示例。
在下文中一共展示了Flask.config['UPLOAD_DIRECTORY']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Flask
# 需要导入模块: from flask.app import Flask [as 别名]
# 或者: from flask.app.Flask import config['UPLOAD_DIRECTORY'] [as 别名]
import os
from flask.app import Flask
from flask.helpers import flash
from flask.templating import render_template
from flask_bootstrap import Bootstrap
from flask_transfer.exc import UploadError
from metadata_upload.service import random_string, SAMLMetadataUploadForm, \
SAMLMetadataUpload
app = Flask(__name__)
app.config['UPLOAD_DIRECTORY'] = os.environ.get('MD_UPLOAD_DIR', 'metadata_uploads')
app.secret_key = os.environ.get('MD_UPLOAD_SECRET', random_string())
Bootstrap(app)
@app.route('/', methods=['GET', 'POST'])
def upload():
form = SAMLMetadataUploadForm()
if form.validate_on_submit():
filehandle = form.uploaded_file.data
try:
SAMLMetadataUpload.save(filehandle, upload_directory=app.config['UPLOAD_DIRECTORY'])
flash('Uploaded {}'.format(filehandle.filename), 'success')
except UploadError as e:
flash('{}: {}'.format(filehandle.filename, str(e)), 'error')
elif form.errors:
for field, errors in form.errors.items():
for error in errors: