修复: 使用 current_app 替代 app 访问配置
问题: database.py 中 get_statistics 使用 app.config['TIMEZONE'],
但 app 对象未导入,导致 AttributeError
解决:
1. 导入 current_app: from flask import current_app
2. 使用 current_app.config['TIMEZONE'] 替代 app.config['TIMEZONE']
3. current_app 是 Flask 上下文代理,自动指向当前应用实例
符合 Flask 官方最佳实践
This commit is contained in:
@@ -7,6 +7,7 @@ import json
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import List, Optional, Dict, Any
|
||||
import os
|
||||
from flask import current_app
|
||||
|
||||
|
||||
class Database:
|
||||
@@ -322,7 +323,7 @@ class Database:
|
||||
total = cursor.fetchone()['total']
|
||||
|
||||
# 使用本地时区计算今日和本周的 UTC 时间范围
|
||||
local_tz = pytz.timezone(self.timezone)
|
||||
local_tz = pytz.timezone(current_app.config['TIMEZONE'])
|
||||
local_now = datetime.now(local_tz)
|
||||
|
||||
# 今日本地时间的开始和结束
|
||||
|
||||
Reference in New Issue
Block a user