python - Flask-Uploads 上传文件报错
天蓬老师
天蓬老师 2017-04-17 11:45:32
0
2
850

form 代码如下:

from flask.ext.uploads import UploadSet, IMAGES
from flask_wtf import Form
from flask_wtf.file import FileField, FileAllowed, FileRequired

images = UploadSet('images', IMAGES)

class UploadForm(Form):
    upload = FileField('image', validators=[
        FileRequired(),
        FileAllowed(images, 'Images only!')
    ])

以上代码是完全按照flask_wtf的手册来写的。这样写之后,上传文件的时候报以下错误: RuntimeError: cannot access configuration outside request

难道我还需要在其他地方做什么设置么?谢谢。

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
大家讲道理

I feel like the problem is not in the code you listed. RuntimeError: cannot access configuration outside request means that the setting items can only be accessed during the processing of user requests, and cannot be accessed at other times (such as when initializing the application)

PHPzhong

Solved. flask-uploads needs to add configuration. Just add the following record to the flask configuration file:

UPLOADED_IMAGES_DEST = 'some/path/'
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!