generating empty "a" tags when nested in html templates

Why django generates empty a tags in html templates when nested. Only in ul area and in 1st li child.

test.html:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<nav class="site-nav">
    <ul class="nav-ul">
        {% for item in nav %}
        <li class="nav-li">
            <a class="nav-a" href="{% url item.url %}">
                {{ item.title }}
                {% if item.nested %}
                    <ul class="expand-ul">
                        {% for nested_item in item.nested %}
                        <li class="nested-li">
                            {% if nested_item.tag %}
                            <a href="{% url nested_item.url service_tag=nested_item.tag %}" class="nested-a">
                                {{ nested_item.title }}
                            </a>
                            {% else %}
                            <a href="{{ nested_item.url }}" class="nested-a">
                                {{ nested_item.title }}
                            </a>
                            {% endif %}
                        </li>
                        {% endfor %}
                    </ul>
                {% endif %}
            </a>
        </li>
        {% endfor %}
    </ul>
</nav>
</body>

/=================================================================/
views.py:

from .test_utils import TestMixin

class TestPage(TestMixin, TemplateView):
    template_name = 'test.html'

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        mix_context = self.get_mixin_context()
        context.update(mix_context)
        print('vws>test>context>>>>:', context)
        return context

/=========================================================================/

test_utils.py:

services = [
    {
        'title': 'repair flat',
        'url': 'services',
        'tag': 'repair_flat'
    },
    {
        'title': 'repair house',
        'url': 'services',
        'tag': 'repair_house'
    },
    {
        'title': 'repair prom',
        'url': 'services',
        'tag': 'repair_prom'
    },
]
contacts = [
    {
        'title': 'info@mysite.com',
        'url': 'mailto: info@mysite.com',
    },
    {
        'title': 'google',
        'url': 'https://google.com/',
    },
]

nav = [
    {
        'title': 'HOME',
        'url': 'home',
    },
    {
        'title': 'ABOUT',
        'url': 'about',
    },
    {
        'title': 'SERVICES',
        'url': 'home',
        'nested': services
    },
    {
        'title': 'CONTACTS',
        'url': 'home',
        'nested': contacts
    }
]
class TestMixin:
    def get_mixin_context(self):
        context = dict()
        context['nav'] = nav

        return context

/========================================================================/
when “a” tag not nested it work ok:

Can you post what is being generated when you say it’s not working?

Please, don’t post an image. Copy/paste the html into the body of your post, between lines of three backtick - ` characters like you have done for your code.

I am unable to recreate the symptoms you are describing here. When I render the template you have posted here with the context as supplied, I get the entries rendered appropriately.

The only thing I can think of is that one of the parent classes has added some data to the context that is causing this.

What are you getting from the output of: