RuntimeError: cannot access configuration outside request

后端 未结 1 1809
轮回少年
轮回少年 2021-02-07 04:49

I got following error:

RuntimeError: cannot access configuration outside request

from executing following code:

# -*- coding: u         


        
相关标签:
1条回答
  • 2021-02-07 05:22

    You haven't configured the Flask-Uploads extension. Use the configure_uploads() function to attach your upload sets to your app:

    from flaskext.uploads import UploadSet, configure_uploads
    
    app = Flask(__name__)
    app.config['UPLOADED_CSVFILES_DEST'] = '/var/uploads'
    csvfiles = UploadSet('csvfiles', ('csv',))
    configure_uploads(app, (csvfiles,))
    

    The second argument to UploadSet() takes a sequence of extensions. Don't pass in the file path to an UploadSet; you would use your Flask configuration instead.

    Set UPLOADED_<name-of-your-set>_DEST, where the name is uppercased. Here that's UPLOADED_CSVFILES_DEST. You can also set a UPLOADS_DEFAULT_DEST configuration; it'll be used as a base directory, with separate subdirectories for each set name.

    Alternatively, that 3rd parameter can be a callable:

    configure_uploads(app, (csvfiles,), lambda app: '/var/uploads')
    
    0 讨论(0)
提交回复
热议问题