django自定义标签错误 'my_tag' is not a registered tag library.

Django自定义simple_tag时出错如下:

解决办法:

在settings里的 加上红色的部分,my_tag为自定义的标签函数 后面的为其地址 

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')]
        ,
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
         'libraries':{
                "my_tag":"app02.templates.my_tag",
            },
        },
    },
]
发布了113 篇原创文章 · 获赞 11 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/testManger/article/details/105179844
tag
今日推荐