'my html and css not linking when using 'url_for'

I am creating my first project in web application using python flask.

Now I'm working with my html, but my css is not linking to my html when running with flask.

code when linking the css:

<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main_layout.css')}}">

file directory:

Project
├───static
      ├───main_layout.css
└───templates
      ├───layout.html
├───main.py


Solution 1:[1]

Try this:

filename=‘../static/main_layout.css’

It looks like you are looking for the file in the same directory as the html file. You need to back out one directory and move into the static folder with the link above.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anurag A S