[Fixed]-Django Include file repeating itself in production only

1👍

Below is the correct code. It wasn’t repeating as I thought it was, it was just iterating through my categories from the top down, and then grouping them by categories as they were positioned on the list, which is why I was getting duplicate categories. Adding |dictsort:"category.slug" to my regroup tag and .list in my for loop fixed the issue.

{% regroup tools|dictsort:"category.slug" by category as grouped %}
<ul class="c-sidebar-menu collapse " id="sidebar-menu-1">
  {% for category in grouped %}
    <li class="c-dropdown c-active c-open">
      <a href="javascript:;" class="c-toggler">{{ category.grouper|capfirst }} <span class="c-arrow"></span> </a>
      <ul class="c-dropdown-menu">
        {% for t in category.list %}
          {% if t.category == category.grouper %}
          <li>
            <a href="{% url 'tool_detail' category=t.category slug=t.slug %}">{{ t.title }}</a>
          </li>
          {% endif %}
        {% endfor %}
      </ul>
    </li>
  {% endfor %}
</ul>

Leave a comment