Answer the question
In order to leave comments, you need to log in
Custom template tag how to create 'list_product' is not a registered tag library.?
In general, my application needs the ability to display the value of a variable (queryset). Googling on the Internet, I realized that I need to create my own tag. I also found documentation on this topic, but unfortunately it did not help me.
Tag function
from django import template
from products.models import Genre
register = template.Library()
@register.simple_tag
def list_product(request):
return {'gerne':Genre.objects.all()}
{% load list_product %}
{% for i in list_product%}
{{ i }}
{% endfor %}
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',
'home.template_tags.base_tag.list_product', # путь к моей папке
],
},
},
]
TemplateSyntaxError at /
'list_product' is not a registered tag library. Must be one of:
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question