Skip to content Skip to sidebar Skip to footer

Flask Unable To Resolve Static Files

I am trying to write a simple API using Flask. I am following Miguel Grinberg's blog. I have a use-case where I am trying to serve a static page. I am unable to serve the static w

Solution 1:

The template needs to be in a folder called templates. So the correct solution should be

flask_application/
   - templates/
     - index.html 

You can read the documentation for the render_template method.

Solution 2:

If you don't care about renderung a template, you can just send the static file on your route. This way you can just leave everything in the static directory.

app.send_static_file('index.html')

Just remember the rest of the assets will need to be referenced as /static/<asset>, ie <script src="/static/js/jquery.js></script>

Post a Comment for "Flask Unable To Resolve Static Files"