diff --git a/fzjgact/huodong/templates/base.html b/fzjgact/huodong/templates/base.html index 1fc896d..b349e34 100644 --- a/fzjgact/huodong/templates/base.html +++ b/fzjgact/huodong/templates/base.html @@ -13,11 +13,9 @@
- 分支机构活动管理 + 分支机构活动管理 {{ ''|get_current_year }}年
- {{ ''|get_current_year }}年 -
- 统计周期:{{ ''|get_statistic_period }} + 统计周期:{{ ''|get_statistic_period }}
diff --git a/fzjgact/huodong/templatetags/__pycache__/custom_filters.cpython-311.pyc b/fzjgact/huodong/templatetags/__pycache__/custom_filters.cpython-311.pyc index e5930c7..b384739 100644 Binary files a/fzjgact/huodong/templatetags/__pycache__/custom_filters.cpython-311.pyc and b/fzjgact/huodong/templatetags/__pycache__/custom_filters.cpython-311.pyc differ diff --git a/fzjgact/huodong/templatetags/custom_filters.py b/fzjgact/huodong/templatetags/custom_filters.py index 6d778f5..a3fd47c 100644 --- a/fzjgact/huodong/templatetags/custom_filters.py +++ b/fzjgact/huodong/templatetags/custom_filters.py @@ -35,7 +35,11 @@ def get_current_year(value=None): """ 获取当前年份 """ - now = datetime.now() if value is None else value + # 只有当value是datetime对象时才使用它,否则使用当前时间 + if isinstance(value, datetime): + now = value + else: + now = datetime.now() return now.year @@ -48,7 +52,11 @@ def get_statistic_period(value=None): - 在2026年2月,实际统计的是2025年12月至2026年2月 - 以此类推 """ - now = datetime.now() if value is None else value + # 只有当value是datetime对象时才使用它,否则使用当前时间 + if isinstance(value, datetime): + now = value + else: + now = datetime.now() current_year = now.year current_month = now.month