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 tag

Akhilesh Gandhe
Akhilesh Gandhe
1,177 Points

Doubt with static files library

Here one thing I cannot understand is that in the work space is that we have different files for layout.html and home.html but here in the objective test all are in one place..am getting confused and also here {% block title %} hello {% endblock %} it is like this {% block content %} <h1> welcome </h1> {% endblock %} I could not understand this as I am new to the Django. Finally what it is being asked in the objective

Please help me with this Thanks

articles/templates/articles/article_list.html
{% load static from staticfiles %}
{% extends 'base.html' %}

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

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

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,722 Points

Check out this reference page: https://docs.djangoproject.com/en/2.0/howto/static-files/

static builds the real path to your stylesheet.

{% load static from staticfiles %}
{% extends 'base.html' %}

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

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