python
config_error
ai_generated
true
配置错误:USE_TZ 为 True 但未设置 TIME_ZONE
django.core.exceptions.ImproperlyConfigured: USE_TZ is True but TIME_ZONE is not set
ID: python/django-timezone-aware-error
80%修复率
86%置信度
0证据数
2025-05-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
USE_TZ=True 需要指定 TIME_ZONE 设置。
English
USE_TZ=True requires TIME_ZONE setting to be specified.
解决方案
-
95% 成功率
Set TIME_ZONE = 'UTC' or your local timezone in settings.py.
-
80% 成功率
If you don't need timezone support, set USE_TZ = False.
无效尝试
常见但无效的做法:
-
60% 失败
Setting USE_TZ=False disables timezone support, which may cause datetime inconsistencies.
-
80% 失败
Setting TIME_ZONE='' doesn't satisfy Django; must be a valid timezone string.