I'm using Django 1.2.1 and I'm having problems trying to load my template tags:
{% load mytags %}
TemplateSyntaxError at /myapp/
'mytags' is not a valid tag library: Template library mytags not
found, tried django.templatetags.mytags
It's defined in myproject/myapp/templatetags/mytags.py
.
nate@nate-desktop:~/work/django-projects/myproject$ ls myapp/templatetags/
mytags.py __init.py__
nate@nate-desktop:~/work/django-projects/myproject$ more
myapp/templatetags/mytags.py
from django import template
register = template.Library()
@register.simple_tag
def myclass(request):
return request.path
I added 'myapp' to INSTALLED_APPS
, and updated TEMPLATE_LOADERS
(as
per a suggestion from StackOverflow):
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
'django.template.loaders.app_directories.load_template_source',
)
When I start the server I see this warning message:
/usr/local/lib/python2.6/dist-packages/django/template/loaders/eggs.py:4:
UserWarning: Module _mysql was already imported from
/usr/lib/pymodules/python2.6/_mysql.so, but
/usr/lib/pymodules/python2.6 is being added to sys.path
When I try to import my module in the shell I also am unable to import it:
>>> from django.templatetags import mytags
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: cannot import name mytags
>>> from myapp.templatetags import mytags
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named templatetags
Does this mean something is wrong with my path or setup? Any ideas?
A note for others who run into this: you need to restart the development server to register new files in your django app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With