From cd99b1bc4f907de4591686bb3e7f6bfb2fa2134b Mon Sep 17 00:00:00 2001 From: PCoder Date: Tue, 4 Jun 2024 17:07:38 +0530 Subject: [PATCH] Check variable before accessing attribute --- publichealth/home/templatetags/navigation.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/publichealth/home/templatetags/navigation.py b/publichealth/home/templatetags/navigation.py index 7082a43..9d984e9 100644 --- a/publichealth/home/templatetags/navigation.py +++ b/publichealth/home/templatetags/navigation.py @@ -54,12 +54,13 @@ def top_menu(context, parent, calling_page=None): menuitems = parent.get_children().live().in_menu().specific() for menuitem in menuitems: menuitem.show_dropdown = has_menu_children(menuitem) - menuitem.active = (calling_page.url.startswith(menuitem.url) - if calling_page else False) - try: - menuitem.title = menuitem.trans_title - except AttributeError: - pass + if calling_page: + menuitem.active = (calling_page.url.startswith(menuitem.url) + if calling_page else False) + try: + menuitem.title = menuitem.trans_title + except AttributeError: + pass return { 'calling_page': calling_page, 'menuitems': menuitems,