que estoy usando Django 1.2.1 y estoy teniendo problemas al intentar cargar mis etiquetas de plantilla:Django: No se puede cargar etiquetas de plantilla
{% load mytags %}
TemplateSyntaxError at /myapp/
'mytags' is not a valid tag library: Template library mytags not
found, tried django.templatetags.mytags
Se define en myproject/myapp/templatetags/mytags.py
.
[email protected]:~/work/django-projects/myproject$ ls myapp/templatetags/
mytags.py __init.py__
[email protected]:~/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
añadí 'miaplicacion' a INSTALLED_APPS
y actualizan TEMPLATE_LOADERS
(como por una sugerencia de 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',
)
Cuando inicio el servidor veo este mensaje de advertencia:
/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
Cuando intento importar mi módulo en el shell tampoco puedo importarlo:
>>> 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
¿Esto significa que algo está mal en mi ruta o configuración? ¿Algunas ideas?
¿También tiene un '__init __. Py' en el directorio' myapp'? – Wolph
Buena pregunta. Sí, lo hago: nate @ nate-desktop: ~/work/django-projects/myproject $ ls myapp/ __init__.py models.py templatetags views.py __init __. Pyc models.pyc tests.py views.pyc –
Tengo dificultades para ingresar el resultado de 'ls'. Los guiones bajos se convierten en texto en negrita. Debería mostrar doble guion bajo init.py doble guion bajo. –