diff --git a/judgments/templatetags/navigation_tags.py b/judgments/templatetags/navigation_tags.py index d5549924..e4186854 100644 --- a/judgments/templatetags/navigation_tags.py +++ b/judgments/templatetags/navigation_tags.py @@ -1,5 +1,5 @@ from django import template -from django.urls import resolve +from django.urls import Resolver404, resolve register = template.Library() @@ -8,7 +8,12 @@ def navigation_item_class(context, path): request = context.get("request") - if request and resolve(request.path_info).url_name == path: + try: + request_path = resolve(request.path_info).url_name + except Resolver404: + request_path = None + + if request and request_path and request_path == path: return "govuk-header__navigation-item govuk-header__navigation-item--active" return "govuk-header__navigation-item"