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

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 27,816 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 %}