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 Django Basics Django Templates Static Assets

Wadzanai Mufunde
PLUS
Wadzanai Mufunde
Courses Plus Student 9,174 Points

My css file cannot be found by Django

So here is my settings.py file:

STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'assets/'), )

Here is my home.html:

{% extends "layout.html" %}

{% block title %} Well hello there! {% endblock%}

{% block content%} <h1>Home Page</h1> {% endblock %}

And here is my layout.html:

{% load static from staticfiles %} <!doctype html> <html> <head> <title>{%block title %} {% endblock %}</title> <link rel="stylesheet" href="{% static 'css/layout.css' %}"> </head> <body> <div class="site-container"> {% block content%} {% endblock %} </div> </body> </html>

I am using this on my own machine and the console tells me that the CSS file gives me a 404 error - it's not found. What do I do?

1 Answer

Aldo Rivadeneira
Aldo Rivadeneira
3,241 Points

The settings configuration looks good to me. Inside the home.html idk if the double quotes could make something, but you can change to single quotes like the following

{% extends 'layout.html' %}

{% block title %}Well hello there! {% endblock %}

{% block content %}
    <h1>Welcome!</h1>
{% endblock %}

Maybe since you had the problem, you solve it by now.