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 Complex Template Tags

Server error 'not a registered tag library' when rendering site for Complex Template Tags. Redone to teacher's code 4X.

Here's the website description:

Request Method: GET
Request URL:    http://port-8000-c9y6cyrl64.treehouse-app.com/
Django Version: 1.9.9
Exception Type: TemplateSyntaxError
Exception Value:    
'course_extras' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_static
admin_urls
cache
future
humanize
i18n
l10n
log
static
staticfiles
tz
Exception Location: /usr/local/pyenv/versions/3.5.0/lib/python3.5/site-packages/django/template/defaulttags.py in find_library, line 1136
Python Executable:  /usr/local/pyenv/versions/3.5.0/bin/python
Python Version: 3.5.0
Python Path:    
['/home/treehouse/workspace/learning_site',
 '/usr/local/pyenv/versions/3.5.0/lib/python35.zip',
 '/usr/local/pyenv/versions/3.5.0/lib/python3.5',
 '/usr/local/pyenv/versions/3.5.0/lib/python3.5/plat-linux',
 '/usr/local/pyenv/versions/3.5.0/lib/python3.5/lib-dynload',
 '/usr/local/pyenv/versions/3.5.0/lib/python3.5/site-packages']
Server time:    Fri, 21 Jul 2017 13:53:32 -0700

Here's course_extras.py

from django import template

from courses.models import Course


register = template.Library()

@register.simple_tag
def newest_course():
    ''' Gets the most recent course added to the Library. '''
    return Course.objects.latest('created_at')

@register.inclusion_tag('courses/course_nav.html')
def nav_courses_list():
    ''' Returns dictionary of courses to display as navigation pane '''
    courses = Course.objects.all()
    return {'courses': courses}

<head-desk>

[MOD: added ```python formatting -cf]

Chris Freeman: <head-desk> is not part of the code. That is a cryptic piece of an illustration of me pounding my head into my desk over this situation. I'm sorry it got added to the code I was working with, it does not belong there.

Here's the source of the exception, layout.html:

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

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

[MOD: added ```html+jinja formatting -cf]

Chris Freeman
Chris Freeman
Treehouse Moderator 68,425 Points

What is the <head-desk> in the course_extras.py file? It could be stopping the compilation of the file course_extras.py which would case the library not to be found.

1 Answer

Solved. Added '{% load course_extras %}' both course_detail.html and step_detail.html. This wasn't covered in the video so it's surprising that the instructor's example passed the rules engine when without it, the current engine fails the code.