from django import template
from django.urls import reverse

register = template.Library()

@register.simple_tag
def nav_active(request, url):
    if request.path == reverse(url):
        return 'active'
    return ''

@@ -144,41 +144,198 @@
     
-if request.path == reverse(url):%0A
+current_url = request.path%0A    reverse_url = reverse(url)%0A    if reverse_url in current_url:%0A        # Handle sub-path and root-path%0A        if reverse_url != '/' or current_url == '/':%0A    
     

Handle sub-path and root-path