4.0.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. ============================================
  2. Django 4.0 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. *Expected December 2021*
  5. Welcome to Django 4.0!
  6. These release notes cover the :ref:`new features <whats-new-4.0>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-4.0>` you'll
  8. want to be aware of when upgrading from Django 3.2 or earlier. We've
  9. :ref:`begun the deprecation process for some features
  10. <deprecated-features-4.0>`.
  11. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  12. project.
  13. Python compatibility
  14. ====================
  15. Django 4.0 supports Python 3.8, 3.9, and 3.10. We **highly recommend** and only
  16. officially support the latest release of each series.
  17. The Django 3.2.x series is the last to support Python 3.6 and 3.7.
  18. .. _whats-new-4.0:
  19. What's new in Django 4.0
  20. ========================
  21. Functional unique constraints
  22. -----------------------------
  23. The new :attr:`*expressions <django.db.models.UniqueConstraint.expressions>`
  24. positional argument of
  25. :class:`UniqueConstraint() <django.db.models.UniqueConstraint>` enables
  26. creating functional unique constraints on expressions and database functions.
  27. For example::
  28. from django.db import models
  29. from django.db.models import UniqueConstraint
  30. from django.db.models.functions import Lower
  31. class MyModel(models.Model):
  32. first_name = models.CharField(max_length=255)
  33. last_name = models.CharField(max_length=255)
  34. class Meta:
  35. indexes = [
  36. UniqueConstraint(
  37. Lower('first_name'),
  38. Lower('last_name').desc(),
  39. name='first_last_name_unique',
  40. ),
  41. ]
  42. Functional unique constraints are added to models using the
  43. :attr:`Meta.constraints <django.db.models.Options.constraints>` option.
  44. ``scrypt`` password hasher
  45. --------------------------
  46. The new :ref:`scrypt password hasher <scrypt-usage>` is more secure and
  47. recommended over PBKDF2. However, it's not the default as it requires OpenSSL
  48. 1.1+ and more memory.
  49. Redis cache backend
  50. -------------------
  51. The new ``django.core.cache.backends.redis.RedisCache`` cache backend provides
  52. built-in support for caching with Redis. `redis-py`_ 3.0.0 or higher is
  53. required. For more details, see the :ref:`documentation on caching with Redis
  54. in Django <redis>`.
  55. .. _`redis-py`: https://pypi.org/project/redis/
  56. Minor features
  57. --------------
  58. :mod:`django.contrib.admin`
  59. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60. * The ``admin/base.html`` template now has a new block ``header`` which
  61. contains the admin site header.
  62. * The new :meth:`.ModelAdmin.get_formset_kwargs` method allows customizing the
  63. keyword arguments passed to the constructor of a formset.
  64. * The navigation sidebar now has a quick filter toolbar.
  65. * The new context variable ``model`` which contains the model class for each
  66. model is added to the :meth:`.AdminSite.each_context` method.
  67. * The new :attr:`.ModelAdmin.search_help_text` attribute allows specifying a
  68. descriptive text for the search box.
  69. * The :attr:`.InlineModelAdmin.verbose_name_plural` attribute now fallbacks to
  70. the :attr:`.InlineModelAdmin.verbose_name` + ``'s'``.
  71. :mod:`django.contrib.admindocs`
  72. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. * The admindocs now allows esoteric setups where :setting:`ROOT_URLCONF` is not
  74. a string.
  75. * The model section of the ``admindocs`` now shows cached properties.
  76. :mod:`django.contrib.auth`
  77. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. * The default iteration count for the PBKDF2 password hasher is increased from
  79. 260,000 to 320,000.
  80. * The new
  81. :attr:`LoginView.next_page <django.contrib.auth.views.LoginView.next_page>`
  82. attribute and
  83. :meth:`~django.contrib.auth.views.LoginView.get_default_redirect_url` method
  84. allow customizing the redirect after login.
  85. :mod:`django.contrib.contenttypes`
  86. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. * ...
  88. :mod:`django.contrib.gis`
  89. ~~~~~~~~~~~~~~~~~~~~~~~~~
  90. * Added support for SpatiaLite 5.
  91. * :class:`~django.contrib.gis.gdal.GDALRaster` now allows creating rasters in
  92. any GDAL virtual filesystem.
  93. :mod:`django.contrib.messages`
  94. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. * ...
  96. :mod:`django.contrib.postgres`
  97. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  98. * The PostgreSQL backend now supports connecting by a service name. See
  99. :ref:`postgresql-connection-settings` for more details.
  100. * The new :class:`~django.contrib.postgres.operations.AddConstraintNotValid`
  101. operation allows creating check constraints on PostgreSQL without verifying
  102. that all existing rows satisfy the new constraint.
  103. * The new :class:`~django.contrib.postgres.operations.ValidateConstraint`
  104. operation allows validating check constraints which were created using
  105. :class:`~django.contrib.postgres.operations.AddConstraintNotValid` on
  106. PostgreSQL.
  107. * The new
  108. :class:`ArraySubquery() <django.contrib.postgres.expressions.ArraySubquery>`
  109. expression allows using subqueries to construct lists of values on
  110. PostgreSQL.
  111. :mod:`django.contrib.redirects`
  112. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  113. * ...
  114. :mod:`django.contrib.sessions`
  115. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  116. * ...
  117. :mod:`django.contrib.sitemaps`
  118. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. * ...
  120. :mod:`django.contrib.sites`
  121. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122. * ...
  123. :mod:`django.contrib.staticfiles`
  124. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  125. * :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage` now
  126. replaces paths to JavaScript source map references with their hashed
  127. counterparts.
  128. * :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage` now
  129. replaces paths to JavaScript modules in ``import`` and ``export`` statements
  130. with their hashed counterparts.
  131. * The new ``manifest_storage`` argument of
  132. :class:`~django.contrib.staticfiles.storage.ManifestFilesMixin` and
  133. :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage`
  134. allows customizing the manifest file storage.
  135. :mod:`django.contrib.syndication`
  136. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  137. * ...
  138. Cache
  139. ~~~~~
  140. * The new async API for ``django.core.cache.backends.base.BaseCache`` begins
  141. the process of making cache backends async-compatible. The new async methods
  142. all have ``a`` prefixed names, e.g. ``aadd()``, ``aget()``, ``aset()``,
  143. ``aget_or_set()``, or ``adelete_many()``.
  144. Going forward, the ``a`` prefix will be used for async variants of methods
  145. generally.
  146. CSRF
  147. ~~~~
  148. * CSRF protection now consults the ``Origin`` header, if present. To facilitate
  149. this, :ref:`some changes <csrf-trusted-origins-changes-4.0>` to the
  150. :setting:`CSRF_TRUSTED_ORIGINS` setting are required.
  151. Decorators
  152. ~~~~~~~~~~
  153. * ...
  154. Email
  155. ~~~~~
  156. * ...
  157. Error Reporting
  158. ~~~~~~~~~~~~~~~
  159. * ...
  160. File Storage
  161. ~~~~~~~~~~~~
  162. * ...
  163. File Uploads
  164. ~~~~~~~~~~~~
  165. * ...
  166. Forms
  167. ~~~~~
  168. * :class:`~django.forms.ModelChoiceField` now includes the provided value in
  169. the ``params`` argument of a raised
  170. :exc:`~django.core.exceptions.ValidationError` for the ``invalid_choice``
  171. error message. This allows custom error messages to use the ``%(value)s``
  172. placeholder.
  173. * :class:`~django.forms.formsets.BaseFormSet` now renders non-form errors with
  174. an additional class of ``nonform`` to help distinguish them from
  175. form-specific errors.
  176. * :class:`~django.forms.formsets.BaseFormSet` now allows customizing the widget
  177. used when deleting forms via
  178. :attr:`~django.forms.formsets.BaseFormSet.can_delete` by setting the
  179. :attr:`~django.forms.formsets.BaseFormSet.deletion_widget` attribute or
  180. overriding :meth:`~django.forms.formsets.BaseFormSet.get_deletion_widget`
  181. method.
  182. Generic Views
  183. ~~~~~~~~~~~~~
  184. * :class:`~django.views.generic.edit.DeleteView` now uses
  185. :class:`~django.views.generic.edit.FormMixin`, allowing you to provide a
  186. :class:`~django.forms.Form` subclass, with a checkbox for example, to confirm
  187. deletion. In addition, this allows ``DeleteView`` to function with
  188. :class:`django.contrib.messages.views.SuccessMessageMixin`.
  189. Internationalization
  190. ~~~~~~~~~~~~~~~~~~~~
  191. * ...
  192. Logging
  193. ~~~~~~~
  194. * The alias of the database used in an SQL call is now passed as extra context
  195. along with each message to the :ref:`django-db-logger` logger.
  196. Management Commands
  197. ~~~~~~~~~~~~~~~~~~~
  198. * The :djadmin:`runserver` management command now supports the
  199. :option:`--skip-checks` option.
  200. * On PostgreSQL, :djadmin:`dbshell` now supports specifying a password file.
  201. * The :djadmin:`shell` command now respects :py:data:`sys.__interactivehook__`
  202. at startup. This allows loading shell history between interactive sessions.
  203. As a consequence, ``readline`` is no longer loaded if running in *isolated*
  204. mode.
  205. * The new :attr:`BaseCommand.suppressed_base_arguments
  206. <django.core.management.BaseCommand.suppressed_base_arguments>` attribute
  207. allows suppressing unsupported default command options in the help output.
  208. * The new :option:`startapp --exclude` and :option:`startproject --exclude`
  209. options allow excluding directories from the template.
  210. Migrations
  211. ~~~~~~~~~~
  212. * ...
  213. Models
  214. ~~~~~~
  215. * New :meth:`QuerySet.contains(obj) <.QuerySet.contains>` method returns
  216. whether the queryset contains the given object. This tries to perform the
  217. query in the simplest and fastest way possible.
  218. * The new ``precision`` argument of the
  219. :class:`Round() <django.db.models.functions.Round>` database function allows
  220. specifying the number of decimal places after rounding.
  221. * :meth:`.QuerySet.bulk_create` now sets the primary key on objects when using
  222. SQLite 3.35+.
  223. * :class:`~django.db.models.DurationField` now supports multiplying and
  224. dividing by scalar values on SQLite.
  225. * :meth:`.QuerySet.bulk_update` now returns the number of objects updated.
  226. * The new :attr:`.Aggregate.empty_aggregate_value` attribute allows specifying
  227. a value to return when the aggregation is used over an empty result set.
  228. * The ``skip_locked`` argument of :meth:`.QuerySet.select_for_update()` is now
  229. allowed on MariaDB 10.6+.
  230. * :class:`~django.db.models.Lookup` expressions may now be used in ``QuerySet``
  231. annotations, aggregations, and directly in filters.
  232. * The new :ref:`default <aggregate-default>` argument for built-in aggregates
  233. allows specifying a value to be returned when the queryset (or grouping)
  234. contains no entries, rather than ``None``.
  235. Requests and Responses
  236. ~~~~~~~~~~~~~~~~~~~~~~
  237. * The :class:`~django.middleware.security.SecurityMiddleware` now adds the
  238. :ref:`Cross-Origin Opener Policy <cross-origin-opener-policy>` header with a
  239. value of ``'same-origin'`` to prevent cross-origin popups from sharing the
  240. same browsing context. You can prevent this header from being added by
  241. setting the :setting:`SECURE_CROSS_ORIGIN_OPENER_POLICY` setting to ``None``.
  242. Security
  243. ~~~~~~~~
  244. * ...
  245. Serialization
  246. ~~~~~~~~~~~~~
  247. * ...
  248. Signals
  249. ~~~~~~~
  250. * The new ``stdout`` argument for :func:`~django.db.models.signals.pre_migrate`
  251. and :func:`~django.db.models.signals.post_migrate` signals allows redirecting
  252. output to a stream-like object. It should be preferred over
  253. :py:data:`sys.stdout` and :py:func:`print` when emitting verbose output in
  254. order to allow proper capture when testing.
  255. Templates
  256. ~~~~~~~~~
  257. * :tfilter:`floatformat` template filter now allows using the ``u`` suffix to
  258. force disabling localization.
  259. Tests
  260. ~~~~~
  261. * The new ``serialized_aliases`` argument of
  262. :func:`django.test.utils.setup_databases` determines which
  263. :setting:`DATABASES` aliases test databases should have their state
  264. serialized to allow usage of the
  265. :ref:`serialized_rollback <test-case-serialized-rollback>` feature.
  266. * Django test runner now supports a :option:`--buffer <test --buffer>` option
  267. with parallel tests.
  268. * The new ``logger`` argument to :class:`~django.test.runner.DiscoverRunner`
  269. allows a Python :py:ref:`logger <logger>` to be used for logging.
  270. * The new :meth:`.DiscoverRunner.log` method provides a way to log messages
  271. that uses the ``DiscoverRunner.logger``, or prints to the console if not set.
  272. * Django test runner now supports a :option:`--shuffle <test --shuffle>` option
  273. to execute tests in a random order.
  274. * The :option:`test --parallel` option now supports the value ``auto`` to run
  275. one test process for each processor core.
  276. * :meth:`.TestCase.captureOnCommitCallbacks` now captures new callbacks added
  277. while executing :func:`.transaction.on_commit` callbacks.
  278. URLs
  279. ~~~~
  280. * ...
  281. Utilities
  282. ~~~~~~~~~
  283. * ...
  284. Validators
  285. ~~~~~~~~~~
  286. * ...
  287. .. _backwards-incompatible-4.0:
  288. Backwards incompatible changes in 4.0
  289. =====================================
  290. Database backend API
  291. --------------------
  292. This section describes changes that may be needed in third-party database
  293. backends.
  294. * ``DatabaseOperations.year_lookup_bounds_for_date_field()`` and
  295. ``year_lookup_bounds_for_datetime_field()`` methods now take the optional
  296. ``iso_year`` argument in order to support bounds for ISO-8601 week-numbering
  297. years.
  298. * The second argument of ``DatabaseSchemaEditor._unique_sql()`` and
  299. ``_create_unique_sql()`` methods is now fields instead of columns.
  300. :mod:`django.contrib.gis`
  301. -------------------------
  302. * Support for PostGIS 2.3 is removed.
  303. * Support for GDAL 2.0 and GEOS 3.5 is removed.
  304. Dropped support for PostgreSQL 9.6
  305. ----------------------------------
  306. Upstream support for PostgreSQL 9.6 ends in November 2021. Django 4.0 supports
  307. PostgreSQL 10 and higher.
  308. Dropped support for Oracle 12.2 and 18c
  309. ---------------------------------------
  310. Upstream support for Oracle 12.2 ends in March 2022 and for Oracle 18c it ends
  311. in June 2021. Django 3.2 will be supported until April 2024. Django 4.0
  312. officially supports Oracle 19c.
  313. .. _csrf-trusted-origins-changes-4.0:
  314. ``CSRF_TRUSTED_ORIGINS`` changes
  315. --------------------------------
  316. Format change
  317. ~~~~~~~~~~~~~
  318. Values in the :setting:`CSRF_TRUSTED_ORIGINS` setting must include the scheme
  319. (e.g. ``'http://'`` or ``'https://'``) instead of only the hostname.
  320. Also, values that started with a dot, must now also include an asterisk before
  321. the dot. For example, change ``'.example.com'`` to ``'https://*.example.com'``.
  322. A system check detects any required changes.
  323. Configuring it may now be required
  324. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  325. As CSRF protection now consults the ``Origin`` header, you may need to set
  326. :setting:`CSRF_TRUSTED_ORIGINS`, particularly if you allow requests from
  327. subdomains by setting :setting:`CSRF_COOKIE_DOMAIN` (or
  328. :setting:`SESSION_COOKIE_DOMAIN` if :setting:`CSRF_USE_SESSIONS` is enabled) to
  329. a value starting with a dot.
  330. ``SecurityMiddleware`` no longer sets the ``X-XSS-Protection`` header
  331. ---------------------------------------------------------------------
  332. The :class:`~django.middleware.security.SecurityMiddleware` no longer sets the
  333. ``X-XSS-Protection`` header if the ``SECURE_BROWSER_XSS_FILTER`` setting is
  334. ``True``. The setting is removed.
  335. Most modern browsers don't honor the ``X-XSS-Protection`` HTTP header. You can
  336. use Content-Security-Policy_ without allowing ``'unsafe-inline'`` scripts
  337. instead.
  338. If you want to support legacy browsers and set the header, use this line in a
  339. custom middleware::
  340. response.headers.setdefault('X-XSS-Protection', '1; mode=block')
  341. .. _Content-Security-Policy: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
  342. Migrations autodetector changes
  343. -------------------------------
  344. The migrations autodetector now uses model states instead of model classes.
  345. Also, migration operations for ``ForeignKey`` and ``ManyToManyField`` fields no
  346. longer specify attributes which were not passed to the fields during
  347. initialization.
  348. As a side-effect, running ``makemigrations`` might generate no-op
  349. ``AlterField`` operations for ``ManyToManyField`` and ``ForeignKey`` fields in
  350. some cases.
  351. Miscellaneous
  352. -------------
  353. * Support for ``cx_Oracle`` < 7.0 is removed.
  354. * To allow serving a Django site on a subpath without changing the value of
  355. :setting:`STATIC_URL`, the leading slash is removed from that setting (now
  356. ``'static/'``) in the default :djadmin:`startproject` template.
  357. * The :class:`~django.contrib.admin.AdminSite` method for the admin ``index``
  358. view is no longer decorated with ``never_cache`` when accessed directly,
  359. rather than via the recommended ``AdminSite.urls`` property, or
  360. ``AdminSite.get_urls()`` method.
  361. * Unsupported operations on a sliced queryset now raise ``TypeError`` instead
  362. of ``AssertionError``.
  363. * The undocumented ``django.test.runner.reorder_suite()`` function is renamed
  364. to ``reorder_tests()``. It now accepts an iterable of tests rather than a
  365. test suite, and returns an iterator of tests.
  366. * Calling ``FileSystemStorage.delete()`` with an empty ``name`` now raises
  367. ``ValueError`` instead of ``AssertionError``.
  368. * Calling ``EmailMultiAlternatives.attach_alternative()`` or
  369. ``EmailMessage.attach()`` with an invalid ``content`` or ``mimetype``
  370. arguments now raise ``ValueError`` instead of ``AssertionError``.
  371. * :meth:`~django.test.SimpleTestCase.assertHTMLEqual` no longer considers a
  372. non-boolean attribute without a value equal to an attribute with the same
  373. name and value.
  374. * Tests that fail to load, for example due to syntax errors, now always match
  375. when using :option:`test --tag`.
  376. * The undocumented ``django.contrib.admin.utils.lookup_needs_distinct()``
  377. function is renamed to ``lookup_spawns_duplicates()``.
  378. * The undocumented ``HttpRequest.get_raw_uri()`` method is removed. The
  379. :meth:`.HttpRequest.build_absolute_uri` method may be a suitable alternative.
  380. * The ``object`` argument of undocumented ``ModelAdmin.log_addition()``,
  381. ``log_change()``, and ``log_deletion()`` methods is renamed to ``obj``.
  382. * :class:`~django.utils.feedgenerator.RssFeed`,
  383. :class:`~django.utils.feedgenerator.Atom1Feed`, and their subclasses now
  384. emit elements with no content as self-closing tags.
  385. * ``NodeList.render()`` no longer casts the output of ``render()`` method for
  386. individual nodes to a string. ``Node.render()`` should always return a string
  387. as documented.
  388. * The ``where_class`` property of ``django.db.models.sql.query.Query`` and the
  389. ``where_class`` argument to the private ``get_extra_restriction()`` method of
  390. ``ForeignObject`` and ``ForeignObjectRel`` are removed. If needed, initialize
  391. ``django.db.models.sql.where.WhereNode`` instead.
  392. * The ``filter_clause`` argument of the undocumented ``Query.add_filter()``
  393. method is replaced by two positional arguments ``filter_lhs`` and
  394. ``filter_rhs``.
  395. * :class:`~django.middleware.csrf.CsrfViewMiddleware` now uses
  396. ``request.META['CSRF_COOKIE_NEEDS_UPDATE']`` in place of
  397. ``request.META['CSRF_COOKIE_USED']``, ``request.csrf_cookie_needs_reset``,
  398. and ``response.csrf_cookie_set`` to track whether the CSRF cookie should be
  399. sent. This is an undocumented, private API.
  400. * The undocumented ``TRANSLATOR_COMMENT_MARK`` constant is moved from
  401. ``django.template.base`` to ``django.utils.translation.template``.
  402. * The ``real_apps`` argument of the undocumented
  403. ``django.db.migrations.state.ProjectState.__init__()`` method must now be a
  404. set if provided.
  405. * :class:`~django.forms.RadioSelect` and
  406. :class:`~django.forms.CheckboxSelectMultiple` widgets are now rendered in
  407. ``<div>`` tags so they are announced more concisely by screen readers. If you
  408. need the previous behavior, :ref:`override the widget template
  409. <overriding-built-in-widget-templates>` with the appropriate template from
  410. Django 3.2.
  411. * The :tfilter:`floatformat` template filter no longer depends on the
  412. ``USE_L10N`` setting and always returns localized output. Use the ``u``
  413. suffix to disable localization.
  414. * The default value of the ``USE_L10N`` setting is changed to ``True``. See the
  415. :ref:`Localization section <use_l10n_deprecation>` above for more details.
  416. .. _deprecated-features-4.0:
  417. Features deprecated in 4.0
  418. ==========================
  419. Time zone support
  420. -----------------
  421. In order to follow good practice, the default value of the :setting:`USE_TZ`
  422. setting will change from ``False`` to ``True``, and time zone support will be
  423. enabled by default, in Django 5.0.
  424. Note that the default :file:`settings.py` file created by
  425. :djadmin:`django-admin startproject <startproject>` includes
  426. :setting:`USE_TZ = True <USE_TZ>` since Django 1.4.
  427. You can set ``USE_TZ`` to ``False`` in your project settings before then to
  428. opt-out.
  429. .. _use_l10n_deprecation:
  430. Localization
  431. ------------
  432. In order to follow good practice, the default value of the ``USE_L10N`` setting
  433. is changed from ``False`` to ``True``.
  434. Moreover ``USE_L10N`` is deprecated as of this release. Starting with Django
  435. 5.0, by default, any date or number displayed by Django will be localized.
  436. The :ttag:`{% localize %} <localize>` tag and the :tfilter:`localize`/
  437. :tfilter:`unlocalize` filters will still be honored by Django.
  438. Miscellaneous
  439. -------------
  440. * ``SERIALIZE`` test setting is deprecated as it can be inferred from the
  441. :attr:`~django.test.TestCase.databases` with the
  442. :ref:`serialized_rollback <test-case-serialized-rollback>` option enabled.
  443. * The undocumented ``django.utils.baseconv`` module is deprecated.
  444. * The undocumented ``django.utils.datetime_safe`` module is deprecated.
  445. * The default sitemap protocol for sitemaps built outside the context of a
  446. request will change from ``'http'`` to ``'https'`` in Django 5.0.
  447. * The ``extra_tests`` argument for :meth:`.DiscoverRunner.build_suite` and
  448. :meth:`.DiscoverRunner.run_tests` is deprecated.
  449. * The :class:`~django.contrib.postgres.aggregates.ArrayAgg`,
  450. :class:`~django.contrib.postgres.aggregates.JSONBAgg`, and
  451. :class:`~django.contrib.postgres.aggregates.StringAgg` aggregates will return
  452. ``None`` when there are no rows instead of ``[]``, ``[]``, and ``''``
  453. respectively in Django 5.0. If you need the previous behavior, explicitly set
  454. ``default`` to ``Value([])``, ``Value('[]')``, or ``Value('')``.
  455. Features removed in 4.0
  456. =======================
  457. These features have reached the end of their deprecation cycle and are removed
  458. in Django 4.0.
  459. See :ref:`deprecated-features-3.0` for details on these changes, including how
  460. to remove usage of these features.
  461. * ``django.utils.http.urlquote()``, ``urlquote_plus()``, ``urlunquote()``, and
  462. ``urlunquote_plus()`` are removed.
  463. * ``django.utils.encoding.force_text()`` and ``smart_text()`` are removed.
  464. * ``django.utils.translation.ugettext()``, ``ugettext_lazy()``,
  465. ``ugettext_noop()``, ``ungettext()``, and ``ungettext_lazy()`` are removed.
  466. * ``django.views.i18n.set_language()`` doesn't set the user language in
  467. ``request.session`` (key ``_language``).
  468. * ``alias=None`` is required in the signature of
  469. ``django.db.models.Expression.get_group_by_cols()`` subclasses.
  470. * ``django.utils.text.unescape_entities()`` is removed.
  471. * ``django.utils.http.is_safe_url()`` is removed.
  472. See :ref:`deprecated-features-3.1` for details on these changes, including how
  473. to remove usage of these features.
  474. * The ``PASSWORD_RESET_TIMEOUT_DAYS`` setting is removed.
  475. * The :lookup:`isnull` lookup no longer allows using non-boolean values as the
  476. right-hand side.
  477. * The ``django.db.models.query_utils.InvalidQuery`` exception class is removed.
  478. * The ``django-admin.py`` entry point is removed.
  479. * The ``HttpRequest.is_ajax()`` method is removed.
  480. * Support for the pre-Django 3.1 encoding format of cookies values used by
  481. ``django.contrib.messages.storage.cookie.CookieStorage`` is removed.
  482. * Support for the pre-Django 3.1 password reset tokens in the admin site (that
  483. use the SHA-1 hashing algorithm) is removed.
  484. * Support for the pre-Django 3.1 encoding format of sessions is removed.
  485. * Support for the pre-Django 3.1 ``django.core.signing.Signer`` signatures
  486. (encoded with the SHA-1 algorithm) is removed.
  487. * Support for the pre-Django 3.1 ``django.core.signing.dumps()`` signatures
  488. (encoded with the SHA-1 algorithm) in ``django.core.signing.loads()`` is
  489. removed.
  490. * Support for the pre-Django 3.1 user sessions (that use the SHA-1 algorithm)
  491. is removed.
  492. * The ``get_response`` argument for
  493. ``django.utils.deprecation.MiddlewareMixin.__init__()`` is required and
  494. doesn't accept ``None``.
  495. * The ``providing_args`` argument for ``django.dispatch.Signal`` is removed.
  496. * The ``length`` argument for ``django.utils.crypto.get_random_string()`` is
  497. required.
  498. * The ``list`` message for ``ModelMultipleChoiceField`` is removed.
  499. * Support for passing raw column aliases to ``QuerySet.order_by()`` is removed.
  500. * The ``NullBooleanField`` model field is removed, except for support in
  501. historical migrations.
  502. * ``django.conf.urls.url()`` is removed.
  503. * The ``django.contrib.postgres.fields.JSONField`` model field is removed,
  504. except for support in historical migrations.
  505. * ``django.contrib.postgres.fields.jsonb.KeyTransform`` and
  506. ``django.contrib.postgres.fields.jsonb.KeyTextTransform`` are removed.
  507. * ``django.contrib.postgres.forms.JSONField`` is removed.
  508. * The ``{% ifequal %}`` and ``{% ifnotequal %}`` template tags are removed.
  509. * The ``DEFAULT_HASHING_ALGORITHM`` transitional setting is removed.