4👍
Solved it using inclusion tags.
Created custom tag in the templatetags/tags.py
file
from django import template
from flowers.models import Category
register = template.Library()
@register.inclusion_tag('_partials/nav.html')
def show_categories():
categories = Category.objects.all()
print categories
return {'categories':categories}
Created template for it in the _partials/nav.html
file
<nav>
<ul>
{% for category in categories %}
<li><a href="{% url 'category:detail' category.id' %}">{{ category.name }}</a></li>
{% endfor %}
</ul>
</nav>
At the end, used that tag
{% load tags %}
{% show_categories %}
Source:stackexchange.com