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

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

[bash] 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 [/bash]

Solution :

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

[bash] ‘libraries’: { ‘staticfiles’: ‘django.templatetags.static’, }, [/bash]

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

[bash] 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’, }, }, }, ] [/bash]

Leave a Comment