blog/templatetags/blog_tags.py
from django import template
from ..models import Category
register = template.Library()
@register.simple_tag
def total_categories():
category_list = Category.objects.filter(published=True, )
return category_list
templates/post_list.html
<head>
{% load mptt_tags %}
{% load blog_tags %}
<meta charset="UTF-8">
<title>Title</title>
</head>
pycharmpro/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'page',
'menu1',
'mptt',
'blog',
]
ОШИБКА: django.template.exceptions.TemplateSyntaxError: 'blog_tags' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_urls
cache
i18n
l10n
log
mptt_admin
mptt_tags
static
tz