More than one static path in local Flask instance

后端 未结 4 1158
生来不讨喜
生来不讨喜 2020-12-02 11:11

Is that possible to add more static paths for my local dev Flask instance? I want to have default static folder for storing js/css/images files for the site and

4条回答
  •  有刺的猬
    2020-12-02 11:53

    I have been using following approach:

    # Custom static data
    @app.route('/cdn/')
    def custom_static(filename):
        return send_from_directory(app.config['CUSTOM_STATIC_PATH'], filename)
    

    The CUSTOM_STATIC_PATH variable is defined in my configuration.

    And in templates:

    {{ url_for('custom_static', filename='foo') }}
    

    Caveat emptor - I'm not really sure whether it's secure ;)

提交回复
热议问题