Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Django Basics Django Templates Static tag

Aleksandar Kosev
Aleksandar Kosev
4,603 Points

Now that we have the tag available, we can use it in our <link> tag. Use {% static %} to reference the "css/styles

HELP!

articles/templates/articles/article_list.html
{% extends 'base.html' %}
{% load static from staticfiles %}
{% block static %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
{% endblock %}

{% block content %}
{% for article in articles %}
{{ article.headline }}
{% endfor %}
{% endblock %}

9 Answers

Chris Grazioli
Chris Grazioli
31,225 Points

@Aurélien Debord

Try making 'css/styles.css' its been a whie but I think thats what ended up working for this project. For some reason the style sheet is plural??

Quentin Durantay
Quentin Durantay
17,880 Points

Try this:

<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}>

{% %} is when you want to execute Python code, {{ }} is when you want to use a Python variable.

Aleksandar Kosev
Aleksandar Kosev
4,603 Points

Nop:/ it is still giving me "Didn't find the correct {% static %} tag."

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

url_for is a Flask macro, not a Django template tag.

Chris Grazioli
Chris Grazioli
31,225 Points

Kenneth Love whats the deal here? the grader doesn't seem to accept the correct answer. I thought I copied exactly what the video taught.

<link rel="stylesheet" href="{% static 'css/style.css' %}">

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Double check the instructions for the stylesheet's filename.

Chris Grazioli
Chris Grazioli
31,225 Points

apparently I misspelled it here but in my code it was correct, but still not passing.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I just passed it this morning with your code, the correct filename, and importing the static tag. I'm not sure what could be going wrong outside of those things.

Chris Grazioli
Chris Grazioli
31,225 Points

It's says Use {% static %} to reference the "css/styles.css" file in the href attribute of the <link> tag. What are we missing?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher
<link rel="stylesheet" href="{% static 'css/style.css' %}">
                                                 ^
Chris Grazioli
Chris Grazioli
31,225 Points

@Kenneth Love thats exactly what I entered, three different times, I even skipped this section and Its spelled out exactly the same as your saying and I'm typing, later on in the course.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

The instructions say to link styles.css (as in more than one style), not style.css. You misspelled the filename.

Chris Grazioli
Chris Grazioli
31,225 Points

That's really weird! Spent the day brewing today, I'll take a look again tomorrow, but I tried it both ways several times yesterday and with much Aggravation ito my worked as I explained above.

Hello everybody,

I try this and it does not work. Can you tell me what is wrong ?

<link rel="stylesheet" href="{% static 'css/style.css' %}">

Chris Grazioli
Chris Grazioli
31,225 Points

SOLVED

<link rel="stylesheet" href="{% static 'css/styles.css' %}"> -- doesn't work but the grader will accept <link rel="stylesheet" href="{% static "css/styles.css" %}"> for some reason

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

I've tested both <link rel="stylesheet" href="{% static 'css/styles.css' %}"> and <link rel="stylesheet" href="{% static "css/styles.css" %}"> and they both pass. Even <link rel="stylesheet" href="{%static'css/styles.css'%}"> is passing.

nasir iqbal
nasir iqbal
2,546 Points

this is the correct answer rel="stylesheet" href="{% static "css/styles.css" %}"> other answers doesnt work for exp <link rel="stylesheet" href="{% static 'css/styles.css' %}">