More than one static path in local Flask instance

后端 未结 4 1184
生来不讨喜
生来不讨喜 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:59

    You can use a Blueprint with its own static dir http://flask.pocoo.org/docs/blueprints/

    Blueprint

    blueprint = Blueprint('site', __name__, static_url_path='/static/site', static_folder='path/to/files')
    app.register_blueprint(blueprint)
    

    Template

    {{ url_for('site.static', filename='filename') }}
    

提交回复
热议问题