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

Greg Kaleka
Greg Kaleka
39,021 Points

TemplateSyntaxError at / Invalid block tag on line 9: 'static'. Did you forget to register or load this tag?

Not sure why I'm getting this error. My code is identical to Kenneth's, except that I used a list instead of tuple for STATICFILES_DIRS, because I'm using a newer version of Django.

I'm using my local environment rather than Workspaces.

Here are just the pertinent parts of my files for this lesson:

STATIC_URL = '/static/'
    os.path.join(BASE_DIR, 'assets'),
urlpatterns = [
    url(r'^courses/', include('courses.urls')),
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.homepage),

urlpatterns += staticfiles_urlpatterns()
%{ load static from staticfiles %}

<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>{% block title %}{% endblock %}</title>
    <link rel="stylesheet" type="text/css" href="{% static 'css/layout.css' %}">

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Greg,

In layout.html on line 1, it seems you have the incorrect syntax for the opening template tag. You have %{ when it should be {%.

This is causing the template error on line 9 because the static template tag hasn't been successfully loaded.

Greg Kaleka
Greg Kaleka
39,021 Points

:unamused: it's always the little things that get you, isn't it?


Ryan S
Ryan S
27,276 Points

For sure. I personally find the % key and curly braces combination to be a little awkward. I'm always stumbling on typos in my template tags.