mirror of https://github.com/django/django.git
Refs #32379 -- Changed default USE_TZ to True.
Per deprecation timeline.
This commit is contained in:
parent
4aa0689080
commit
602d9a312f
|
@ -237,14 +237,6 @@ class Settings:
|
||||||
setattr(self, setting, setting_value)
|
setattr(self, setting, setting_value)
|
||||||
self._explicit_settings.add(setting)
|
self._explicit_settings.add(setting)
|
||||||
|
|
||||||
if self.USE_TZ is False and not self.is_overridden("USE_TZ"):
|
|
||||||
warnings.warn(
|
|
||||||
"The default value of USE_TZ will change from False to True "
|
|
||||||
"in Django 5.0. Set USE_TZ to False in your project settings "
|
|
||||||
"if you want to keep the current default behavior.",
|
|
||||||
category=RemovedInDjango50Warning,
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.is_overridden("USE_DEPRECATED_PYTZ"):
|
if self.is_overridden("USE_DEPRECATED_PYTZ"):
|
||||||
warnings.warn(USE_DEPRECATED_PYTZ_DEPRECATED_MSG, RemovedInDjango50Warning)
|
warnings.warn(USE_DEPRECATED_PYTZ_DEPRECATED_MSG, RemovedInDjango50Warning)
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ ALLOWED_HOSTS = []
|
||||||
TIME_ZONE = "America/Chicago"
|
TIME_ZONE = "America/Chicago"
|
||||||
|
|
||||||
# If you set this to True, Django will use timezone-aware datetimes.
|
# If you set this to True, Django will use timezone-aware datetimes.
|
||||||
USE_TZ = False
|
USE_TZ = True
|
||||||
|
|
||||||
# RemovedInDjango50Warning: It's a transitional setting helpful in migrating
|
# RemovedInDjango50Warning: It's a transitional setting helpful in migrating
|
||||||
# from pytz tzinfo to ZoneInfo(). Set True to continue using pytz tzinfo
|
# from pytz tzinfo to ZoneInfo(). Set True to continue using pytz tzinfo
|
||||||
|
|
|
@ -2929,11 +2929,7 @@ See also :setting:`DECIMAL_SEPARATOR`, :setting:`NUMBER_GROUPING` and
|
||||||
``USE_TZ``
|
``USE_TZ``
|
||||||
----------
|
----------
|
||||||
|
|
||||||
Default: ``False``
|
Default: ``True``
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
In Django 5.0, the default value will change from ``False`` to ``True``.
|
|
||||||
|
|
||||||
A boolean that specifies if datetimes will be timezone-aware by default or not.
|
A boolean that specifies if datetimes will be timezone-aware by default or not.
|
||||||
If this is set to ``True``, Django will use timezone-aware datetimes internally.
|
If this is set to ``True``, Django will use timezone-aware datetimes internally.
|
||||||
|
@ -2944,11 +2940,9 @@ be retained if present.
|
||||||
|
|
||||||
See also :setting:`TIME_ZONE`, :setting:`USE_I18N` and :setting:`USE_L10N`.
|
See also :setting:`TIME_ZONE`, :setting:`USE_I18N` and :setting:`USE_L10N`.
|
||||||
|
|
||||||
.. note::
|
.. versionchanged:: 5.0
|
||||||
|
|
||||||
The default :file:`settings.py` file created by
|
In older versions, the default value is ``False``.
|
||||||
:djadmin:`django-admin startproject <startproject>` includes
|
|
||||||
``USE_TZ = True`` for convenience.
|
|
||||||
|
|
||||||
.. setting:: USE_X_FORWARDED_HOST
|
.. setting:: USE_X_FORWARDED_HOST
|
||||||
|
|
||||||
|
|
|
@ -261,6 +261,9 @@ to remove usage of these features.
|
||||||
|
|
||||||
* The undocumented ``django.utils.datetime_safe`` module is removed.
|
* The undocumented ``django.utils.datetime_safe`` module is removed.
|
||||||
|
|
||||||
|
* The default value of the ``USE_TZ`` setting is changed from ``False`` to
|
||||||
|
``True``.
|
||||||
|
|
||||||
See :ref:`deprecated-features-4.1` for details on these changes, including how
|
See :ref:`deprecated-features-4.1` for details on these changes, including how
|
||||||
to remove usage of these features.
|
to remove usage of these features.
|
||||||
|
|
||||||
|
|
|
@ -24,23 +24,17 @@ or under bill your customers by one hour, twice a year, every year. The
|
||||||
solution to this problem is to use UTC in the code and use local time only when
|
solution to this problem is to use UTC in the code and use local time only when
|
||||||
interacting with end users.
|
interacting with end users.
|
||||||
|
|
||||||
Time zone support is disabled by default. To enable it, set :setting:`USE_TZ =
|
Time zone support is enabled by default. To disable it, set :setting:`USE_TZ =
|
||||||
True <USE_TZ>` in your settings file.
|
False <USE_TZ>` in your settings file.
|
||||||
|
|
||||||
.. note::
|
.. versionchanged:: 5.0
|
||||||
|
|
||||||
In Django 5.0, time zone support will be enabled by default.
|
In older version, time zone support was disabled by default.
|
||||||
|
|
||||||
Time zone support uses :mod:`zoneinfo`, which is part of the Python standard
|
Time zone support uses :mod:`zoneinfo`, which is part of the Python standard
|
||||||
library from Python 3.9. The ``backports.zoneinfo`` package is automatically
|
library from Python 3.9. The ``backports.zoneinfo`` package is automatically
|
||||||
installed alongside Django if you are using Python 3.8.
|
installed alongside Django if you are using Python 3.8.
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
The default :file:`settings.py` file created by :djadmin:`django-admin
|
|
||||||
startproject <startproject>` includes :setting:`USE_TZ = True <USE_TZ>`
|
|
||||||
for convenience.
|
|
||||||
|
|
||||||
If you're wrestling with a particular problem, start with the :ref:`time zone
|
If you're wrestling with a particular problem, start with the :ref:`time zone
|
||||||
FAQ <time-zones-faq>`.
|
FAQ <time-zones-faq>`.
|
||||||
|
|
||||||
|
|
|
@ -348,25 +348,9 @@ class SettingsTests(SimpleTestCase):
|
||||||
with self.assertRaisesMessage(ValueError, "Incorrect timezone setting: test"):
|
with self.assertRaisesMessage(ValueError, "Incorrect timezone setting: test"):
|
||||||
settings._setup()
|
settings._setup()
|
||||||
|
|
||||||
def test_use_tz_false_deprecation(self):
|
|
||||||
settings_module = ModuleType("fake_settings_module")
|
|
||||||
settings_module.SECRET_KEY = "foo"
|
|
||||||
sys.modules["fake_settings_module"] = settings_module
|
|
||||||
msg = (
|
|
||||||
"The default value of USE_TZ will change from False to True in "
|
|
||||||
"Django 5.0. Set USE_TZ to False in your project settings if you "
|
|
||||||
"want to keep the current default behavior."
|
|
||||||
)
|
|
||||||
try:
|
|
||||||
with self.assertRaisesMessage(RemovedInDjango50Warning, msg):
|
|
||||||
Settings("fake_settings_module")
|
|
||||||
finally:
|
|
||||||
del sys.modules["fake_settings_module"]
|
|
||||||
|
|
||||||
def test_use_deprecated_pytz_deprecation(self):
|
def test_use_deprecated_pytz_deprecation(self):
|
||||||
settings_module = ModuleType("fake_settings_module")
|
settings_module = ModuleType("fake_settings_module")
|
||||||
settings_module.USE_DEPRECATED_PYTZ = True
|
settings_module.USE_DEPRECATED_PYTZ = True
|
||||||
settings_module.USE_TZ = True
|
|
||||||
sys.modules["fake_settings_module"] = settings_module
|
sys.modules["fake_settings_module"] = settings_module
|
||||||
try:
|
try:
|
||||||
with self.assertRaisesMessage(
|
with self.assertRaisesMessage(
|
||||||
|
|
Loading…
Reference in New Issue