Python Django TemplateTags未编译

Python Django TemplateTags未编译,python,django,templatetags,django-oscar,Python,Django,Templatetags,Django Oscar,我正在尝试为我的项目创建自定义django templatetags。我按照可用的指南创建了标签。但是这些标签没有被捡起来。 它们甚至没有被编译(因为没有生成.pyc文件) 结构是my\u dir>app>templatetags>markup\u tags.py。文件夹app和templatetags具有所需的\uuuu init\uuuuuu.py文件 我的markup_tags.py文件是 from django import template from random import ran

我正在尝试为我的项目创建自定义django templatetags。我按照可用的指南创建了标签。但是这些标签没有被捡起来。 它们甚至没有被编译(因为没有生成
.pyc
文件)

结构是
my\u dir>app>templatetags>markup\u tags.py
。文件夹
app
templatetags
具有所需的
\uuuu init\uuuuuu.py
文件

我的markup_tags.py文件是

from django import template
from random import randint

register = template.Library()

@register.assignment_tag()
def random_number(length=3):
    """
    Create a random integer with given length.
    For a length of 3 it will be between 100 and 999.
    For a length of 4 it will be between 1000 and 9999.
    """
    return randint(10**(length-1), (10**(length)-1))
当我使用
python manage.py shell
命令检查标记时:

from my_dir.app.templatetags import markup_tags
我得到一个错误:

Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named templatetags
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
ImportError:没有名为templatetags的模块
这里怎么了?谢谢

编辑:文件夹结构为

所以我不知道出了什么问题,但是python没有接收到我复制到应用程序目录中的
templatetags
文件夹。我删除了它,并使用我的IDE(
PyCharm
),在我的应用程序中创建了一个新的
Python包
,它会自动生成一个新的
\uuuu init\uuuuu.py
文件


我重新启动了我的服务器,现在似乎可以工作了。不过很奇怪

在我通过添加下面的代码解决问题之前,我遇到了相同的问题
在settings.py中

TEMPLATE_LOADERS = ('django.template.loaders.app_directories.load_template_source',
)
将你的应用程序添加到
INSTALLED_APPS = ('myapp',)

并确保在“myapp”文件夹和templatetags中都有一个。

templatetags
包/目录中是否有
\uuuu init\uuuuuuuuuy.py
templatetags
目录包含一个空白的
\uuuuu init\uuuuuu.py
文件。以及通向最终模块的所有父目录/包?@JamesMills不确定这是什么意思。但是我的项目正在使用有问题的
应用程序
(应用程序中的模型是专门使用的)。我还在项目中为标记创建了一个新的应用程序,但是标记文件夹也没有在那里找到。请回答您的问题,并包括应用程序/文件夹结构的
sys.path
pstree
__init__.py