Django unable to find my custom template tags?
Asked Answered
M

1

0

I'm creating custom template tags for my django site. I've followed the django documentation for this and have created a templatetags directory in my main application.

/project/apps/core/templatetags
                 -/__init__.py
                 -/core_extras.py

Since I am not sure if this is causing the problem, I should note I have this in my settings.py

sys.path.insert(0, join(PROJECT_ROOT, "apps"))
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_evolution',
'apps.core',
)

core_extras.py

from django import template
import settings

register = template.Library()

class SiteNameNode(template.Node):
def __init__(self):

def render(self, context):
    site_name = getarrr(settings, "SITE_NAME", false)
    if not site_name:
        return "<!-- SITE_NAME not setting in Settings -->"
    if settings.DEBUG:
        return 'Debug || ' + site_name
    return site_name
@register.tag(name="site_name")
def find_site_name(parser, token):
return SiteNameNode()

main.html

{% load core_extras %}

Error

In template /cygdrive/d/Users/Kin/BitNami DjangoStack projects/flipfinder/templates/main.html, error at line 1
'core_extras' is not a valid tag library: Template library core_extras not found, tried django.templatetags.core_extras,django.contrib.admin.templatetags.core_extras

Has anyone else run into a problem like this? Am I missing something obvious. I've went through and double checked everything, but I can't seem to find anyone with a similar problem.

Mummery answered 18/11, 2011 at 4:9 Comment(3)
just to make sure did you put an init.py in both your core and apps folder ?Acidimeter
Yes, all of my apps are confirmed working before I tried to load the custom tag.Mummery
Tip: Go into the shell and try to from apps.core.templatetags import core_extras - if there's an error in the file, that'll tell you the real one. Like sdolan said in his answer, django's template system is horrid at reporting the real errorsJapeth
M
3

It's failing to import because of a syntax error. Django's templating system just swallows it up.

This line:

site_name = getarrr(settings, "SITE_NAME", false)

should be:

site_name = getattr(settings, "SITE_NAME", false)
Maynord answered 18/11, 2011 at 4:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.