S
S
sortfact3332021-04-01 20:18:23
Django
sortfact333, 2021-04-01 20:18:23

How to display the model on all pages?

I have a model that I display in the header through for, but I don't like what I write in each function. I tried using templatetags
Categorie.objects.all().order_by('id')

@register.simple_tag(takes_context=True)
def header_categories(context):
  return Categorie.objects.all().order_by('id')

but it doesn't work in the template.
{%header_categories%}
  {% for cat in header_categories %}
    cat.text
  {% endfor %}

How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2021-04-01
@dimonchik2013

this is not a model, but a queryset type, put the template where you display
it in another template
https://tutorial.djangogirls.org/ru/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question