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 trialJonathan Prada
7,039 PointsI 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
Chris Freeman
Treehouse Moderator 68,454 PointsMarked as Solved
Brecht Philips
8,863 PointsHi 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
Basel Barzanji
Python Web Development Techdegree Graduate 20,706 PointsIn pycharm had the same problem you have to rerun your Tools> manage.py > runserver
Asma Al-Marrikhi
45,525 PointsThe init.py .. should be
__init__.py
so rename the init file
Jonathan Prada
7,039 PointsJonathan Prada
7,039 Pointsfixed it by restarting...