3.1.txt 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. ============================================
  2. Django 3.1 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. *Expected August 2020*
  5. Welcome to Django 3.1!
  6. These release notes cover the :ref:`new features <whats-new-3.1>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-3.1>` you'll
  8. want to be aware of when upgrading from Django 3.0 or earlier. We've
  9. :ref:`dropped some features<removed-features-3.1>` that have reached the end of
  10. their deprecation cycle, and we've :ref:`begun the deprecation process for
  11. some features <deprecated-features-3.1>`.
  12. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  13. project.
  14. Python compatibility
  15. ====================
  16. Django 3.1 supports Python 3.6, 3.7, and 3.8. We **highly recommend** and only
  17. officially support the latest release of each series.
  18. .. _whats-new-3.1:
  19. What's new in Django 3.1
  20. ========================
  21. Asynchronous views and middleware support
  22. -----------------------------------------
  23. Django now supports a fully asynchronous request path, including:
  24. * :ref:`Asynchronous views <async-views>`
  25. * :ref:`Asynchronous middleware <async-middleware>`
  26. * :ref:`Asynchronous tests and test client <async-tests>`
  27. To get started with async views, you need to declare a view using
  28. ``async def``::
  29. async def my_view(request):
  30. await asyncio.sleep(0.5)
  31. return HttpResponse('Hello, async world!')
  32. All asynchronous features are supported whether you are running under WSGI or
  33. ASGI mode. However, there will be performance penalties using async code in
  34. WSGI mode. You can read more about the specifics in :doc:`/topics/async`
  35. documentation.
  36. You are free to mix async and sync views, middleware, and tests as much as you
  37. want. Django will ensure that you always end up with the right execution
  38. context. We expect most projects will keep the majority of their views
  39. synchronous, and only have a select few running in async mode - but it is
  40. entirely your choice.
  41. Django's ORM, cache layer, and other pieces of code that do long-running
  42. network calls do not yet support async access. We expect to add support for
  43. them in upcoming releases. Async views are ideal, however, if you are doing a
  44. lot of API or HTTP calls inside your view, you can now natively do all those
  45. HTTP calls in parallel to considerably speed up your view's execution.
  46. Asynchronous support should be entirely backwards-compatible and we have tried
  47. to ensure that it has no speed regressions for your existing, synchronous code.
  48. It should have no noticeable effect on any existing Django projects.
  49. Minor features
  50. --------------
  51. :mod:`django.contrib.admin`
  52. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. * The new ``django.contrib.admin.EmptyFieldListFilter`` for
  54. :attr:`.ModelAdmin.list_filter` allows filtering on empty values (empty
  55. strings and nulls) in the admin changelist view.
  56. * Filters in the right sidebar of the admin changelist view now contains a link
  57. to clear all filters.
  58. * ``XRegExp`` is upgraded from version 2.0.0 to 3.2.0.
  59. :mod:`django.contrib.admindocs`
  60. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61. * ...
  62. :mod:`django.contrib.auth`
  63. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. * The default iteration count for the PBKDF2 password hasher is increased from
  65. 180,000 to 216,000.
  66. * Added the :setting:`PASSWORD_RESET_TIMEOUT` setting to define the minimum
  67. number of seconds a password reset link is valid for. This is encouraged
  68. instead of deprecated ``PASSWORD_RESET_TIMEOUT_DAYS``, which will be removed
  69. in Django 4.0.
  70. * The password reset mechanism now uses the SHA-256 hashing algorithm. Support
  71. for tokens that use the old hashing algorithm remains until Django 4.0.
  72. :mod:`django.contrib.contenttypes`
  73. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74. * The new :option:`remove_stale_contenttypes --include-stale-apps` option
  75. allows removing stale content types from previously installed apps that have
  76. been removed from :setting:`INSTALLED_APPS`.
  77. :mod:`django.contrib.gis`
  78. ~~~~~~~~~~~~~~~~~~~~~~~~~
  79. * :lookup:`relate` lookup is now supported on MariaDB.
  80. * Added the :attr:`.LinearRing.is_counterclockwise` property.
  81. * :class:`~django.contrib.gis.db.models.functions.AsGeoJSON` is now supported
  82. on Oracle.
  83. * Added the :class:`~django.contrib.gis.db.models.functions.AsWKB` and
  84. :class:`~django.contrib.gis.db.models.functions.AsWKT` functions.
  85. * Added support for PostGIS 3.
  86. :mod:`django.contrib.humanize`
  87. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. * :tfilter:`intword` template filter now supports negative integers.
  89. :mod:`django.contrib.messages`
  90. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91. * ...
  92. :mod:`django.contrib.postgres`
  93. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  94. * The new :class:`~django.contrib.postgres.indexes.BloomIndex` class allows
  95. creating ``bloom`` indexes in the database. The new
  96. :class:`~django.contrib.postgres.operations.BloomExtension` migration
  97. operation installs the ``bloom`` extension to add support for this index.
  98. * :meth:`~django.db.models.Model.get_FOO_display` now supports
  99. :class:`~django.contrib.postgres.fields.ArrayField` and
  100. :class:`~django.contrib.postgres.fields.RangeField`.
  101. * The new :lookup:`rangefield.lower_inc`, :lookup:`rangefield.lower_inf`,
  102. :lookup:`rangefield.upper_inc`, and :lookup:`rangefield.upper_inf` allows
  103. querying :class:`~django.contrib.postgres.fields.RangeField` by a bound type.
  104. * :lookup:`rangefield.contained_by` now supports
  105. :class:`~django.db.models.SmallAutoField`,
  106. :class:`~django.db.models.AutoField`,
  107. :class:`~django.db.models.BigAutoField`,
  108. :class:`~django.db.models.SmallIntegerField`, and
  109. :class:`~django.db.models.DecimalField`.
  110. * :class:`~django.contrib.postgres.search.SearchQuery` now supports
  111. ``'websearch'`` search type on PostgreSQL 11+.
  112. * :class:`SearchQuery.value <django.contrib.postgres.search.SearchQuery>` now
  113. supports query expressions.
  114. * The new :class:`~django.contrib.postgres.search.SearchHeadline` class allows
  115. highlighting search results.
  116. * :lookup:`search` lookup now supports query expressions.
  117. * The new ``cover_density`` parameter of
  118. :class:`~django.contrib.postgres.search.SearchRank` allows ranking by cover
  119. density.
  120. * The new ``normalization`` parameter of
  121. :class:`~django.contrib.postgres.search.SearchRank` allows rank
  122. normalization.
  123. :mod:`django.contrib.redirects`
  124. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  125. * ...
  126. :mod:`django.contrib.sessions`
  127. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  128. * The :setting:`SESSION_COOKIE_SAMESITE` setting now allows ``'None'`` (string)
  129. value to explicitly state that the cookie is sent with all same-site and
  130. cross-site requests.
  131. :mod:`django.contrib.sitemaps`
  132. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  133. * ...
  134. :mod:`django.contrib.sites`
  135. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  136. * ...
  137. :mod:`django.contrib.staticfiles`
  138. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  139. * The :setting:`STATICFILES_DIRS` setting now supports :class:`pathlib.Path`.
  140. :mod:`django.contrib.syndication`
  141. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142. * ...
  143. Cache
  144. ~~~~~
  145. * The :func:`~django.views.decorators.cache.cache_control` decorator and
  146. :func:`~django.utils.cache.patch_cache_control` method now support multiple
  147. field names in the ``no-cache`` directive for the ``Cache-Control`` header,
  148. according to :rfc:`7234#section-5.2.2.2`.
  149. * :meth:`~django.core.caches.cache.delete` now returns ``True`` if the key was
  150. successfully deleted, ``False`` otherwise.
  151. CSRF
  152. ~~~~
  153. * The :setting:`CSRF_COOKIE_SAMESITE` setting now allows ``'None'`` (string)
  154. value to explicitly state that the cookie is sent with all same-site and
  155. cross-site requests.
  156. Email
  157. ~~~~~
  158. * The :setting:`EMAIL_FILE_PATH` setting, used by the :ref:`file email backend
  159. <topic-email-file-backend>`, now supports :class:`pathlib.Path`.
  160. Error Reporting
  161. ~~~~~~~~~~~~~~~
  162. * :class:`django.views.debug.SafeExceptionReporterFilter` now filters sensitive
  163. values from ``request.META`` in exception reports.
  164. * The new :attr:`.SafeExceptionReporterFilter.cleansed_substitute` and
  165. :attr:`.SafeExceptionReporterFilter.hidden_settings` attributes allow
  166. customization of sensitive settings and ``request.META`` filtering in
  167. exception reports.
  168. * The technical 404 debug view now respects
  169. :setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` when applying settings
  170. filtering.
  171. * The new :setting:`DEFAULT_EXCEPTION_REPORTER` allows providing a
  172. :class:`django.views.debug.ExceptionReporter` subclass to customize exception
  173. report generation. See :ref:`custom-error-reports` for details.
  174. File Storage
  175. ~~~~~~~~~~~~
  176. * ``FileSystemStorage.save()`` method now supports :class:`pathlib.Path`.
  177. * :class:`~django.db.models.FileField` and
  178. :class:`~django.db.models.ImageField` now accept a callable for ``storage``.
  179. This allows you to modify the used storage at runtime, selecting different
  180. storages for different environments, for example.
  181. File Uploads
  182. ~~~~~~~~~~~~
  183. * ...
  184. Forms
  185. ~~~~~
  186. * :class:`~django.forms.ModelChoiceIterator`, used by
  187. :class:`~django.forms.ModelChoiceField` and
  188. :class:`~django.forms.ModelMultipleChoiceField`, now uses
  189. :class:`~django.forms.ModelChoiceIteratorValue` that can be used by widgets
  190. to access model instances. See :ref:`iterating-relationship-choices` for
  191. details.
  192. * :class:`django.forms.DateTimeField` now accepts dates in a subset of ISO 8601
  193. datetime formats, including optional timezone (e.g. ``2019-10-10T06:47``,
  194. ``2019-10-10T06:47:23+04:00``, or ``2019-10-10T06:47:23Z``). Additionally, it
  195. now uses ``DATE_INPUT_FORMATS`` in addition to ``DATETIME_INPUT_FORMATS``
  196. when converting a field input to a ``datetime`` value.
  197. * :attr:`.MultiWidget.widgets` now accepts a dictionary which allows
  198. customizing subwidget ``name`` attributes.
  199. * The new :attr:`.BoundField.widget_type` property can be used to dynamically
  200. adjust form rendering based upon the widget type.
  201. Generic Views
  202. ~~~~~~~~~~~~~
  203. * ...
  204. Internationalization
  205. ~~~~~~~~~~~~~~~~~~~~
  206. * The :setting:`LANGUAGE_COOKIE_SAMESITE` setting now allows ``'None'``
  207. (string) value to explicitly state that the cookie is sent with all same-site
  208. and cross-site requests.
  209. * Added support and translations for the Algerian Arabic language.
  210. Logging
  211. ~~~~~~~
  212. * ...
  213. Management Commands
  214. ~~~~~~~~~~~~~~~~~~~
  215. * The new :option:`check --database` option allows specifying database aliases
  216. for running the ``database`` system checks. Previously these checks were
  217. enabled for all configured :setting:`DATABASES` by passing the ``database``
  218. tag to the command.
  219. * The new :option:`migrate --check` option makes the command exit with a
  220. non-zero status when unapplied migrations are detected.
  221. * The new ``returncode`` argument for
  222. :attr:`~django.core.management.CommandError` allows customizing the exit
  223. status for management commands.
  224. * The new :option:`dbshell -- ARGUMENTS <dbshell -->` option allows passing
  225. extra arguments to the command-line client for the database.
  226. * The :djadmin:`flush` and :djadmin:`sqlflush` commands now include SQL to
  227. reset sequences on SQLite.
  228. Migrations
  229. ~~~~~~~~~~
  230. * Migrations are now loaded also from directories without ``__init__.py``
  231. files.
  232. Models
  233. ~~~~~~
  234. * The new :class:`~django.db.models.functions.ExtractIsoWeekDay` function
  235. extracts ISO-8601 week days from :class:`~django.db.models.DateField` and
  236. :class:`~django.db.models.DateTimeField`, and the new :lookup:`iso_week_day`
  237. lookup allows querying by an ISO-8601 day of week.
  238. * :meth:`.QuerySet.explain` now supports:
  239. * ``TREE`` format on MySQL 8.0.16+,
  240. * ``analyze`` option on MySQL 8.0.18+ and MariaDB.
  241. * Added :class:`~django.db.models.PositiveBigIntegerField` which acts much like
  242. a :class:`~django.db.models.PositiveIntegerField` except that it only allows
  243. values under a certain (database-dependent) limit. Values from ``0`` to
  244. ``9223372036854775807`` are safe in all databases supported by Django.
  245. * The new :class:`~django.db.models.RESTRICT` option for
  246. :attr:`~django.db.models.ForeignKey.on_delete` argument of ``ForeignKey`` and
  247. ``OneToOneField`` emulates the behavior of the SQL constraint ``ON DELETE
  248. RESTRICT``.
  249. * :attr:`.CheckConstraint.check` now supports boolean expressions.
  250. * The :meth:`.RelatedManager.add`, :meth:`~.RelatedManager.create`, and
  251. :meth:`~.RelatedManager.set` methods now accept callables as values in the
  252. ``through_defaults`` argument.
  253. * The new ``is_dst`` parameter of the :meth:`.QuerySet.datetimes` determines
  254. the treatment of nonexistent and ambiguous datetimes.
  255. * The new :class:`~django.db.models.F` expression ``bitxor()`` method allows
  256. :ref:`bitwise XOR operation <using-f-expressions-in-filters>`.
  257. * :meth:`.QuerySet.bulk_create` now sets the primary key on objects when using
  258. MariaDB 10.5+.
  259. * The ``DatabaseOperations.sql_flush()`` method now generates more efficient
  260. SQL on MySQL by using ``DELETE`` instead of ``TRUNCATE`` statements for
  261. tables which don't require resetting sequences.
  262. * SQLite functions are now marked as :py:meth:`deterministic
  263. <sqlite3.Connection.create_function>` on Python 3.8+. This allows using them
  264. in check constraints and partial indexes.
  265. Pagination
  266. ~~~~~~~~~~
  267. * :class:`~django.core.paginator.Paginator` can now be iterated over to yield
  268. its pages.
  269. Requests and Responses
  270. ~~~~~~~~~~~~~~~~~~~~~~
  271. * If :setting:`ALLOWED_HOSTS` is empty and ``DEBUG=True``, subdomains of
  272. localhost are now allowed in the ``Host`` header, e.g. ``static.localhost``.
  273. * :meth:`.HttpResponse.set_cookie` and :meth:`.HttpResponse.set_signed_cookie`
  274. now allow using ``samesite='None'`` (string) to explicitly state that the
  275. cookie is sent with all same-site and cross-site requests.
  276. * The new :meth:`.HttpRequest.accepts` method returns whether the request
  277. accepts the given MIME type according to the ``Accept`` HTTP header.
  278. .. _whats-new-security-3.1:
  279. Security
  280. ~~~~~~~~
  281. * The :setting:`SECURE_REFERRER_POLICY` setting now defaults to
  282. ``'same-origin'``. With this configured,
  283. :class:`~django.middleware.security.SecurityMiddleware` sets the
  284. :ref:`referrer-policy` header to ``same-origin`` on all responses that do not
  285. already have it. This prevents the ``Referer`` header being sent to other
  286. origins. If you need the previous behavior, explicitly set
  287. :setting:`SECURE_REFERRER_POLICY` to ``None``.
  288. * The default :class:`django.core.signing.Signer` algorithm is changed to the
  289. SHA-256. Support for signatures made with the old SHA-1 algorithm remains
  290. until Django 4.0.
  291. Also, the new ``algorithm`` parameter of the
  292. :class:`~django.core.signing.Signer` allows customizing the hashing
  293. algorithm.
  294. Serialization
  295. ~~~~~~~~~~~~~
  296. * ...
  297. Signals
  298. ~~~~~~~
  299. * ...
  300. Templates
  301. ~~~~~~~~~
  302. * The renamed :ttag:`translate` and :ttag:`blocktranslate` template tags are
  303. introduced for internationalization in template code. The older :ttag:`trans`
  304. and :ttag:`blocktrans` template tags aliases continue to work, and will be
  305. retained for the foreseeable future.
  306. * The :ttag:`include` template tag now accepts iterables of template names.
  307. Tests
  308. ~~~~~
  309. * :class:`~django.test.SimpleTestCase` now implements the ``debug()`` method to
  310. allow running a test without collecting the result and catching exceptions.
  311. This can be used to support running tests under a debugger.
  312. * The new :setting:`MIGRATE <TEST_MIGRATE>` test database setting allows
  313. disabling of migrations during a test database creation.
  314. * Django test runner now supports a :option:`test --buffer` option to discard
  315. output for passing tests.
  316. * :class:`~django.test.runner.DiscoverRunner` now skips running the system
  317. checks on databases not :ref:`referenced by tests<testing-multi-db>`.
  318. * :class:`~django.test.TransactionTestCase` teardown is now faster on MySQL
  319. due to :djadmin:`flush` command improvements. As a side effect the latter
  320. doesn't automatically reset sequences on teardown anymore. Enable
  321. :attr:`.TransactionTestCase.reset_sequences` if your tests require this
  322. feature.
  323. URLs
  324. ~~~~
  325. * :ref:`Path converters <registering-custom-path-converters>` can now raise
  326. ``ValueError`` in ``to_url()`` to indicate no match when reversing URLs.
  327. Utilities
  328. ~~~~~~~~~
  329. * :func:`~django.utils.encoding.filepath_to_uri` now supports
  330. :class:`pathlib.Path`.
  331. * :func:`~django.utils.dateparse.parse_duration` now supports comma separators
  332. for decimal fractions in the ISO 8601 format.
  333. * :func:`~django.utils.dateparse.parse_datetime`,
  334. :func:`~django.utils.dateparse.parse_duration`, and
  335. :func:`~django.utils.dateparse.parse_time` now support comma separators for
  336. milliseconds.
  337. Validators
  338. ~~~~~~~~~~
  339. * ...
  340. Miscellaneous
  341. ~~~~~~~~~~~~~
  342. * The SQLite backend now supports :class:`pathlib.Path` for the ``NAME``
  343. setting.
  344. * The ``settings.py`` generated by the :djadmin:`startproject` command now uses
  345. :class:`pathlib.Path` instead of :mod:`os.path` for building filesystem
  346. paths.
  347. * The :setting:`TIME_ZONE <DATABASE-TIME_ZONE>` setting is now allowed on
  348. databases that support time zones.
  349. .. _backwards-incompatible-3.1:
  350. Backwards incompatible changes in 3.1
  351. =====================================
  352. Database backend API
  353. --------------------
  354. This section describes changes that may be needed in third-party database
  355. backends.
  356. * ``DatabaseOperations.fetch_returned_insert_columns()`` now requires an
  357. additional ``returning_params`` argument.
  358. * ``connection.timezone`` property is now ``'UTC'`` by default, or the
  359. :setting:`TIME_ZONE <DATABASE-TIME_ZONE>` when :setting:`USE_TZ` is ``True``
  360. on databases that support time zones. Previously, it was ``None`` on
  361. databases that support time zones.
  362. * ``connection._nodb_connection`` property is changed to the
  363. ``connection._nodb_cursor()`` method and now returns a context manager that
  364. yields a cursor and automatically closes the cursor and connection upon
  365. exiting the ``with`` statement.
  366. * ``DatabaseClient.runshell()`` now requires an additional ``parameters``
  367. argument as a list of extra arguments to pass on to the command-line client.
  368. * The ``sequences`` positional argument of ``DatabaseOperations.sql_flush()``
  369. is replaced by the boolean keyword-only argument ``reset_sequences``. If
  370. ``True``, the sequences of the truncated tables will be reset.
  371. * The ``allow_cascade`` argument of ``DatabaseOperations.sql_flush()`` is now a
  372. keyword-only argument.
  373. * The ``using`` positional argument of
  374. ``DatabaseOperations.execute_sql_flush()`` is removed. The method now uses
  375. the database of the called instance.
  376. Dropped support for MariaDB 10.1
  377. --------------------------------
  378. Upstream support for MariaDB 10.1 ends in October 2020. Django 3.1 supports
  379. MariaDB 10.2 and higher.
  380. ``contrib.admin`` browser support
  381. ---------------------------------
  382. The admin no longer supports the legacy Internet Explorer browser. See
  383. :ref:`the admin FAQ <admin-browser-support>` for details on supported browsers.
  384. :attr:`AbstractUser.first_name <django.contrib.auth.models.User.first_name>` ``max_length`` increased to 150
  385. ------------------------------------------------------------------------------------------------------------
  386. A migration for :attr:`django.contrib.auth.models.User.first_name` is included.
  387. If you have a custom user model inheriting from ``AbstractUser``, you'll need
  388. to generate and apply a database migration for your user model.
  389. If you want to preserve the 30 character limit for first names, use a custom
  390. form::
  391. from django import forms
  392. from django.contrib.auth.forms import UserChangeForm
  393. class MyUserChangeForm(UserChangeForm):
  394. first_name = forms.CharField(max_length=30, required=False)
  395. If you wish to keep this restriction in the admin when editing users, set
  396. ``UserAdmin.form`` to use this form::
  397. from django.contrib.auth.admin import UserAdmin
  398. from django.contrib.auth.models import User
  399. class MyUserAdmin(UserAdmin):
  400. form = MyUserChangeForm
  401. admin.site.unregister(User)
  402. admin.site.register(User, MyUserAdmin)
  403. Miscellaneous
  404. -------------
  405. * The cache keys used by :ttag:`cache` and generated by
  406. :func:`~django.core.cache.utils.make_template_fragment_key` are different
  407. from the keys generated by older versions of Django. After upgrading to
  408. Django 3.1, the first request to any previously cached template fragment will
  409. be a cache miss.
  410. * The logic behind the decision to return a redirection fallback or a 204 HTTP
  411. response from the :func:`~django.views.i18n.set_language` view is now based
  412. on the ``Accept`` HTTP header instead of the ``X-Requested-With`` HTTP header
  413. presence.
  414. * The compatibility imports of ``django.core.exceptions.EmptyResultSet`` in
  415. ``django.db.models.query``, ``django.db.models.sql``, and
  416. ``django.db.models.sql.datastructures`` are removed.
  417. * The compatibility import of ``django.core.exceptions.FieldDoesNotExist`` in
  418. ``django.db.models.fields`` is removed.
  419. * The compatibility imports of ``django.forms.utils.pretty_name()`` and
  420. ``django.forms.boundfield.BoundField`` in ``django.forms.forms`` are removed.
  421. * The compatibility imports of ``Context``, ``ContextPopException``, and
  422. ``RequestContext`` in ``django.template.base`` are removed.
  423. * The compatibility import of
  424. ``django.contrib.admin.helpers.ACTION_CHECKBOX_NAME`` in
  425. ``django.contrib.admin`` is removed.
  426. * The :setting:`STATIC_URL` and :setting:`MEDIA_URL` settings set to relative
  427. paths are now prefixed by the server-provided value of ``SCRIPT_NAME`` (or
  428. ``/`` if not set). This change should not affect settings set to valid URLs
  429. or absolute paths.
  430. * :class:`~django.middleware.http.ConditionalGetMiddleware` no longer adds the
  431. ``ETag`` header to responses with an empty
  432. :attr:`~django.http.HttpResponse.content`.
  433. * ``django.utils.decorators.classproperty()`` decorator is made public and
  434. moved to :class:`django.utils.functional.classproperty()`.
  435. * :tfilter:`floatformat` template filter now outputs (positive) ``0`` for
  436. negative numbers which round to zero.
  437. * :attr:`Meta.ordering <django.db.models.Options.ordering>` and
  438. :attr:`Meta.unique_together <django.db.models.Options.unique_together>`
  439. options on models in ``django.contrib`` modules that were formerly tuples are
  440. now lists.
  441. * The admin calendar widget now handles two-digit years according to the Open
  442. Group Specification, i.e. values between 69 and 99 are mapped to the previous
  443. century, and values between 0 and 68 are mapped to the current century.
  444. * Date-only formats are removed from the default list for
  445. :setting:`DATETIME_INPUT_FORMATS`.
  446. * The :class:`~django.forms.FileInput` widget no longer renders with the
  447. ``required`` HTML attribute when initial data exists.
  448. * The undocumented ``django.views.debug.ExceptionReporterFilter`` class is
  449. removed. As per the :ref:`custom-error-reports` documentation, classes to be
  450. used with :setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` needs to inherit from
  451. :class:`django.views.debug.SafeExceptionReporterFilter`.
  452. * The cache timeout set by :func:`~django.views.decorators.cache.cache_page`
  453. decorator now takes precedence over the ``max-age`` directive from the
  454. ``Cache-Control`` header.
  455. * Providing a non-local remote field in the :attr:`.ForeignKey.to_field`
  456. argument now raises :class:`~django.core.exceptions.FieldError`.
  457. * :setting:`SECURE_REFERRER_POLICY` now defaults to ``'same-origin'``. See the
  458. *What's New* :ref:`Security section <whats-new-security-3.1>` above for more
  459. details.
  460. * :djadmin:`check` management command now runs the ``database`` system checks
  461. only for database aliases specified using :option:`check --database` option.
  462. * :djadmin:`migrate` management command now runs the ``database`` system checks
  463. only for a database to migrate.
  464. * The admin CSS classes ``row1`` and ``row2`` are removed in favor of
  465. ``:nth-child(odd)`` and ``:nth-child(even)`` pseudo-classes.
  466. * The :func:`~django.contrib.auth.hashers.make_password` now requires its
  467. argument to be a string or bytes. Other types should be explicitly cast to
  468. one of these.
  469. * The undocumented ``version`` parameter to the
  470. :class:`~django.contrib.gis.db.models.functions.AsKML` function is removed.
  471. * :ref:`JSON and YAML serializers <serialization-formats>`, used by
  472. :djadmin:`dumpdata`, now dump all data with Unicode by default. If you need
  473. the previous behavior, pass ``ensure_ascii=True`` to JSON serializer, or
  474. ``allow_unicode=False`` to YAML serializer.
  475. .. _deprecated-features-3.1:
  476. Features deprecated in 3.1
  477. ==========================
  478. Miscellaneous
  479. -------------
  480. * ``PASSWORD_RESET_TIMEOUT_DAYS`` setting is deprecated in favor of
  481. :setting:`PASSWORD_RESET_TIMEOUT`.
  482. * The undocumented usage of the :lookup:`isnull` lookup with non-boolean values
  483. as the right-hand side is deprecated, use ``True`` or ``False`` instead.
  484. * The barely documented ``django.db.models.query_utils.InvalidQuery`` exception
  485. class is deprecated in favor of
  486. :class:`~django.core.exceptions.FieldDoesNotExist` and
  487. :class:`~django.core.exceptions.FieldError`.
  488. * The ``django-admin.py`` entry point is deprecated in favor of
  489. ``django-admin``.
  490. * The ``HttpRequest.is_ajax()`` method is deprecated as it relied on a
  491. jQuery-specific way of signifying AJAX calls, while current usage tends to
  492. use the JavaScript `Fetch API
  493. <https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API>`_. Depending on
  494. your use case, you can either write your own AJAX detection method, or use
  495. the new :meth:`.HttpRequest.accepts` method if your code depends on the
  496. client ``Accept`` HTTP header.
  497. If you are writing your own AJAX detection method, ``request.is_ajax()`` can
  498. be reproduced exactly as
  499. ``request.headers.get('x-requested-with') == 'XMLHttpRequest'``.
  500. * Passing ``None`` as the first argument to
  501. ``django.utils.deprecation.MiddlewareMixin.__init__()`` is deprecated.
  502. * The encoding format of cookies values used by
  503. :class:`~django.contrib.messages.storage.cookie.CookieStorage` is different
  504. from the format generated by older versions of Django. Support for the old
  505. format remains until Django 4.0.
  506. * The encoding format of sessions is different from the format generated by
  507. older versions of Django. Support for the old format remains until Django
  508. 4.0.
  509. * The purely documentational ``providing_args`` argument for
  510. :class:`~django.dispatch.Signal` is deprecated. If you rely on this
  511. argument as documentation, you can move the text to a code comment or
  512. docstring.
  513. * Calling ``django.utils.crypto.get_random_string()`` without a ``length``
  514. argument is deprecated.
  515. * The ``list`` message for :class:`~django.forms.ModelMultipleChoiceField` is
  516. deprecated in favor of ``invalid_list``.
  517. * The passing of URL kwargs directly to the context by
  518. :class:`~django.views.generic.base.TemplateView` is deprecated. Reference
  519. them in the template with ``view.kwargs`` instead.
  520. * Passing raw column aliases to :meth:`.QuerySet.order_by` is deprecated. The
  521. same result can be achieved by passing aliases in a
  522. :class:`~django.db.models.expressions.RawSQL` instead beforehand.
  523. * The ``NullBooleanField`` model field is deprecated in favor of
  524. ``BooleanField(null=True)``.
  525. .. _removed-features-3.1:
  526. Features removed in 3.1
  527. =======================
  528. These features have reached the end of their deprecation cycle and are removed
  529. in Django 3.1.
  530. See :ref:`deprecated-features-2.2` for details on these changes, including how
  531. to remove usage of these features.
  532. * ``django.utils.timezone.FixedOffset`` is removed.
  533. * ``django.core.paginator.QuerySetPaginator`` is removed.
  534. * A model's ``Meta.ordering`` doesn't affect ``GROUP BY`` queries.
  535. * ``django.contrib.postgres.fields.FloatRangeField`` and
  536. ``django.contrib.postgres.forms.FloatRangeField`` are removed.
  537. * The ``FILE_CHARSET`` setting is removed.
  538. * ``django.contrib.staticfiles.storage.CachedStaticFilesStorage`` is removed.
  539. * The ``RemoteUserBackend.configure_user()`` method requires ``request`` as the
  540. first positional argument.
  541. * Support for ``SimpleTestCase.allow_database_queries`` and
  542. ``TransactionTestCase.multi_db`` is removed.