我在我的 Django 1.8 项目中使用自定义模板标签时遇到问题。这就是发生的事情:
TemplateSyntaxError at /
Invalid block tag: 'custom_foo'
Request Method: GET
Request URL: <...>
Django Version: 1.8.3
Exception Type: TemplateSyntaxError
Exception Value:
Invalid block tag: 'custom_foo'
我的文件夹如下所示:
my_app
|---templatetags
|---__init__.py
myapp_extras.py
和myapp_extras.py
from django import template
register = template.Library()
@register.filter
def custom_foo():
return 'bar'
我正在使用 PyCharm5 进行开发。一定是遗漏了什么。
我的 base.html 模板{% load myapp_extras %}
位于顶部。