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

David Ton-Lai
David Ton-Lai
3,268 Points

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

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

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.

David Ton-Lai
David Ton-Lai
3,268 Points

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

Diane Leigh
Diane Leigh
16,813 Points

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?

Neil Brown
Neil Brown
22,514 Points

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.

Matthew Allcorn
Matthew Allcorn
4,343 Points

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.

Matthew Allcorn
Matthew Allcorn
4,343 Points

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.