Search code examples
pythonhtmlflaskassets

How to run .html file in Flask? - Error Code 404


so my project structure is pretty straight-forward:

Project structure

Here is the code of my app.py:

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')

@app.route('/index')
def index():
    return render_template("index.html")


if __name__ == '__main__':
    app.run(debug = True)

Thus, the website should be build up properly with all designs (when I call the website through the browser-function inside of PyCharm, it loads all properly), but when doing it via app.py I get lots of 404 error like so:

127.0.0.1 - - [21/Mar/2020 23:25:30] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [21/Mar/2020 23:25:30] "GET /vendor/bootstrap/css/bootstrap.min.css HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /vendor/fontawesome-free/css/all.min.css HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /css/grayscale.min.css HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /img/ipad.png HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /img/bg-masthead.jpg HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /vendor/jquery/jquery.min.js HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /vendor/bootstrap/js/bootstrap.bundle.min.js HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /vendor/jquery-easing/jquery.easing.min.js HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /js/grayscale.min.js HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /img/demo-image-01.jpg HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /img/demo-image-02.jpg HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:31] "GET /vendor/jquery-easing/jquery.easing.min.js HTTP/1.1" 404 -
127.0.0.1 - - [21/Mar/2020 23:25:32] "GET /js/grayscale.min.js HTTP/1.1" 404 -

All files are placed in the proper directories, otherwise it wouldn't work when using the inside-browser function, but I can't get why app.py doesn't GET those assets properly.

//EDIT: he index.html should work (prntscr.com/rkdz6k) when executing through the PyCharm browser function, the website loads properly, thus the template is correct. But somehow executing the .html through the app.py doesn't work

Anyone able to help me out?


Solution

  • Fixed it: All folders (as displayed above in the image) don't belong to the templates folder, they shall be part of the "static" folder. The templates folder only contains index.html whereas css, img, js and vendor (in my example (template)) was wrongly placed.

    Now after dragging those 4 files into "static", everything executes with Code 200 and template loads up as it's supposed to do.