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 Customizing Django Templates Building Custom Tags DIY Custom Tags

Jonathan Prada
Jonathan Prada
7,039 Points

I get TemplateSyntaxError [SOLVED]

I followed the video at this link:

https://teamtreehouse.com/library/customizing-django-templates/building-custom-tags/diy-custom-tags

My file structure

-> courses (folder)
    -> templatetags  (folder)
        -> init.py 
        -> course_extras.py

course_extras.py:

from django import template from courses.models import Course

# instantiated the library class
register = template.Library()

# Registers a function as a simple tag.
# Simple tags don't include new templates,
# don't have an end tag, and don't assign
# values to context variables.
@register.simple_tag
def newest_course():
    return Course.objects.latest('created_at')

Layout.html:

{% load static from staticfiles %}
{% load course_extras %}

<html>
<head>
    <title>{% block title %}{% endblock %}</title>
    <link rel="stylesheet" href="{% static 'css/layout.css' %}">
    {% block static %}{% endblock %}
</head>
<body>
<div class="site-container">
    <nav>
        <a href="{% url 'homepage' %}">Home</a>
        <a href="{% url 'list' %}">Courses</a>
    </nav>
    <p>Don't miss our latest course {% newest_course %}</p>
    {% block content %}
{% endblock %}
</div>
</body>
</html>

Error:

TemplateSyntaxError at /
'course_extras' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_static
admin_urls
cache
humanize
i18n
l10n
log
static
staticfiles
tz
Jonathan Prada
Jonathan Prada
7,039 Points

fixed it by restarting...

Brecht Philips
Brecht Philips
8,863 Points

Hi i have the same problem and restarted pycharm a couple of times without no luck.

Can anybody help me?

[SOLVED] if i run it threw terminal with python manage.py runserver i still get the error! But if i run it with pycharm play sign everything works. Strange..

2 Answers

The init.py .. should be

__init__.py

so rename the init file