这是我自定义的 poll_extras.py 文件
from django import template
register = template.Library()
def titless(value):
"""convert a string to upper case"""
return value.title()
register.filter('titless', titless)
我已经在(templatetags>>这个目录包含init .py文件和poll_extras.py文件中创建了这个文件,这个目录也在我的投票应用程序中)
然后我在一个 html 文件中使用了这个标签(名为 >> poll.html)
这是 poll.html 几行
{% extends 'base.html' %}
{% load poll_extras %}
{% block content %}
<h2>{{"vote vage" | titless}}</h2>
<h3>{{question.title}}</h3>
......
现在我收到此错误
'poll_extras' is not a registered tag library.
但我确实注册了
如果有帮助,这里是树
+---ems
| +---static
| | \---css
| | styles.css
| |
| \---templates
| | base.html
| |
| +---auth
| | login.html
| | success.html
| |
| +---employee
| | add.html
| | delete.html
| | detail.html
| | edit.html
| | home.html
| |
| \---polls
| detail.html
| index.html
| poll.html
|
\---polls
| admin.py
| apps.py
| context_processors.py
| models.py
| tests.py
| urls.py
| views.py
| __init__.py
|
+---migrations
| 0001_initial.py
| 0002_auto_20210324_1407.py
| 0003_answer.py
| __init__.py
|
\---templatetags
poll_extras.py
__init__.py