ファイル構造:
_project_
__init__.py
settings/
__init__.py
settings.py
apps/
__init__.py
newapp/
__init__.py
models.py
....
templatetags/
__init__.py
test_tag.py
...
__init__.py
manage.py
test_tag.pyに含まれるもの:
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter
@stringfilter
def lower(value):
return value.lower()
test.htmlに含まれるもの:
{% load test_tag from _project_.apps.newapp.templatetags %}
Django 1.5シェル(python manage.pyシェル):
(InteractiveConsole)
>>> from _project_.apps.newapp.templatetags import test_tag
>>> test_tag.lower("QWERTY")
u'qwerty'
Djangoの1.5設定:
INSTALLED_APPS = (
...
'_project_.apps.newapp',
...
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
しかし、Django1.5は例外TemplateSyntaxErrorを生成します:
'_project_.apps.newapp.templatetags' is not a valid tag library: Template library _project_.apps.newapp.templatetags not found, tried ...
PS:サーバーが再起動し、*。pycファイルが削除されましたが、問題があります。/ project /newapp/ にある'newapp'の場合-すべてOK。