Flask blueprint static directory does not work?

后端 未结 5 1146
攒了一身酷
攒了一身酷 2020-12-08 09:56

According to the Flask readme, blueprint static files are accessible at blueprintname/static. But for some reason, it doesn\'t work.

My blueprint is lik

5条回答
  •  不思量自难忘°
    2020-12-08 10:38

    You probably registered your Blueprint to sit at the root of your site:

    app.register_blueprint(core, url_prefix='')
    

    but the static view in the Blueprint is no different from all your other Blueprint views; it uses that url_prefix value to make the URL unique.

    The core static view is also active, so you now have two routes that want to handle /static/ URLs. So if you are registering your Blueprint without a URL prefix, you have to give one of these two a unique path.

    Either give the Blueprint a custom static_url_path value, or the core Flask app.

提交回复
热议问题