Django

Solved: django.template.exceptions.TemplateSyntaxError: ‘staticfiles’ is not a registered tag library

Pinterest LinkedIn Tumblr

Solved: django.template.exceptions.TemplateSyntaxError: ‘staticfiles’ is not a registered tag library

When working with Django, you may encounter an error as below,

django.template.exceptions.TemplateSyntaxError: 'staticfiles' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_urls
cache
i18n
l10n
log
rest_framework
static
tz

Solution :

This error can be resolved by django_project/settings.py and add libraries as following in TEMPLATES

'libraries': {
                'staticfiles': 'django.templatetags.static',
            },

So, the settings.py may look like as below,

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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': {
                'staticfiles': 'django.templatetags.static',
            },
        },
    },
]