Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Flask Basics Templates and Static Files Static Files

My styles.css isn't being applied

My styles.css isn't being applied, I'm using a local environment with my styles.css file in a 'static' directory. Here is the code for my layout.html

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>{% block title %}Flask Basics{% endblock %}</title>
         <link rel="stylesheet" href="/static/styles.css">
    </head>
<body>
    {% block content %}{% endblock %}
    <p> Brought to you by the fine folks from Treehouse! </p>
</body>
</html>

5 Answers

remove the leading / from the path. for example, if you had a folder called Project, and inside are your html file and another folder called static, and the css is inside the static folder, the correct path would be "static/styles.css" and adding the leading / like you have it will break it and not apply the css file.

Thank you James! I just followed the lesson, but I guess it's different because he's working from the Work Station!

If you use CTRL + SHIFT + R instead of the refresh button you will see the changes in chrome.

Yea, that's not working for me...

<!DOCTYPE html>
<html>
    <head>
        <title>{% block title %}Flask Basics{% endblock %}</title>
        <link rel="stylesheet" href="/static/styles.css">
    </head>

        <body>
            {%block content%}{%endblock%}




        <footer>Brought to you by the fine folks at Treehouse!</footer>
            </body>
</html>

So as you can see, the only difference is the fact that I added a footer..., otherwise the code looks identical to me. Am I missing something? And yes, I tried it without the leading "/" as well with no result...

Everything else has worked as planned in this project.

Kenneth?

I spent ages with the same problem. Turns out there was a typo in the actual "styles.css" file - ":" instead of a ";". Damn stupid mistake.

Hoping to save people the pain and heartbreak AND time that I experienced from a small but important error - check that your STATIC folder is under the project folder and not hiding in the LAYOUTS folder.

Hoping to save people the pain and heartbreak AND time that I experienced from a small but important error - check that your STATIC folder is under the project folder and not hiding in the LAYOUTS folder.