K
K
kiriaam2022-03-09 20:48:52
Django
kiriaam, 2022-03-09 20:48:52

Django 4.0.3 Error: 'news_tags' is not a registered tag library. How to fix?

Friends, just don't beat with sticks, but I just can't figure out how to fix this error:

'news_tags' is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log static tz

I understand that this is a ridiculous question for experienced specialists, but I ask everyone to help.

Specific:

news/templates/templatags/news_tags.py

from django import template

from news.models import Category

register = template.Library()

@register.simple_tag
def get_categories():
    return Category.objects.all()


templates/inc/_sidebar.html
{% load news_tags %} #ругается на эту часть
  
  <div class="list-group">
      {% get_categories as categories %}
      {% for item in categories %}
      <a href="{% url 'category' item.pk %}" class="list-group-item list-group-item-action">{{ item.title }}</a>
      {% endfor %}
  </div>


settings.py
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',
            ],

        },
    },
]


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

There is something similar here, but it didn't help.
https://qna.habr.com/q/741559

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2022-03-09
@kiriaam

why templatetags inside templates?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question