Flask, Keep getting 404 serving static files using send_static_file

后端 未结 5 780
星月不相逢
星月不相逢 2020-12-28 13:46

I followed the instructions from How to serve static files in Flask, but still couldn\'t get it working.

Here\'s my project structure:

Project_path           


        
5条回答
  •  猫巷女王i
    2020-12-28 14:12

    for me this one worked :

    @app.route('/static/')
    def serve_static(filename):
        root_dir = os.path.dirname(os.getcwd())
        return send_from_directory(os.path.join(root_dir, 'static', 'js'),   filename)       
    

    beside adding this script into init

    app._static_folder = os.path.abspath("static/")
    app = Flask(__name__)
    

    into __init__.py

提交回复
热议问题