From b87ea4c9bd37767a337c8453e5a9f82b01cc35fa Mon Sep 17 00:00:00 2001 From: raiots Date: Mon, 25 Apr 2022 18:56:13 +0800 Subject: [PATCH] fix: KeyError when user do not have todo --- apps/tasks/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/tasks/views.py b/apps/tasks/views.py index 8d2e3a6..7310b8d 100644 --- a/apps/tasks/views.py +++ b/apps/tasks/views.py @@ -127,7 +127,11 @@ class IndexView(View): # 若total_credit为空,不进行以下操作,避免err if total_credit: - current_user = total_credit[request.user.username] + # 暂时解决当该用户当月无任务时,total_credit中不包含该用户的用户名,导致Key Error + try: + current_user = total_credit[request.user.username] + except: + current_user = {} # 累加该部门各个用户的工作量,计算部门工作量 department_cal = {}