1.11.txt 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. =============================================
  2. Django 1.11 release notes - UNDER DEVELOPMENT
  3. =============================================
  4. Welcome to Django 1.11!
  5. These release notes cover the :ref:`new features <whats-new-1.11>`, as well as
  6. some :ref:`backwards incompatible changes <backwards-incompatible-1.11>` you'll
  7. want to be aware of when upgrading from Django 1.10 or older versions. We've
  8. :ref:`begun the deprecation process for some features
  9. <deprecated-features-1.11>`.
  10. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  11. project.
  12. Django 1.11 is designated as a :term:`long-term support release`. It will
  13. receive security updates for at least three years after its release. Support
  14. for the previous LTS, Django 1.8, will end in April 2018.
  15. Python compatibility
  16. ====================
  17. Django 1.11 requires Python 2.7, 3.4, 3.5, or 3.6. Django 1.11 is the first
  18. release to support Python 3.6. We **highly recommend** and only officially
  19. support the latest release of each series.
  20. The Django 1.11.x series is the last to support Python 2. The next major
  21. release, Django 2.0, will only support Python 3.5+.
  22. Deprecating warnings are no longer loud by default
  23. ==================================================
  24. Unlike older versions of Django, Django's own deprecation warnings are no
  25. longer displayed by default. This is consistent with Python's default behavior.
  26. This change allows third-party apps to support both Django 1.11 LTS and Django
  27. 1.8 LTS without having to add code to avoid deprecation warnings.
  28. Following the release of Django 2.0, we suggest that third-party app authors
  29. drop support for all versions of Django prior to 1.11. At that time, you should
  30. be able run your package's tests using ``python -Wd`` so that deprecation
  31. warnings do appear. After making the deprecation warning fixes, your app should
  32. be compatible with Django 2.0.
  33. .. _whats-new-1.11:
  34. What's new in Django 1.11
  35. =========================
  36. Class-based model indexes
  37. -------------------------
  38. The new :mod:`django.db.models.indexes` module contains classes which ease
  39. creating database indexes. Indexes are added to models using the
  40. :attr:`Meta.indexes <django.db.models.Options.indexes>` option.
  41. The :class:`~django.db.models.Index` class creates a b-tree index, as if you
  42. used :attr:`~django.db.models.Field.db_index` on the model field or
  43. :attr:`~django.db.models.Options.index_together` on the model ``Meta`` class.
  44. It can be subclassed to support different index types, such as
  45. :class:`~django.contrib.postgres.indexes.GinIndex`. It also allows defining the
  46. order (ASC/DESC) for the columns of the index.
  47. Template-based widget rendering
  48. -------------------------------
  49. To ease customizing widgets, form widget rendering is now done using the
  50. template system rather than in Python. See :doc:`/ref/forms/renderers`.
  51. You may need to adjust any custom widgets that you've written for a few
  52. :ref:`backwards incompatible changes <template-widget-incompatibilities-1-11>`.
  53. ``Subquery`` expressions
  54. ------------------------
  55. The new :class:`~django.db.models.Subquery` and
  56. :class:`~django.db.models.Exists` database expressions allow creating
  57. explicit subqueries. Subqueries may refer to fields from the outer queryset
  58. using the :class:`~django.db.models.OuterRef` class.
  59. Minor features
  60. --------------
  61. :mod:`django.contrib.admin`
  62. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  63. * :attr:`.ModelAdmin.date_hierarchy` can now reference fields across relations.
  64. * The new :meth:`ModelAdmin.get_exclude()
  65. <django.contrib.admin.ModelAdmin.get_exclude>` hook allows specifying the
  66. exclude fields based on the request or model instance.
  67. * The ``popup_response.html`` template can now be overridden per app, per
  68. model, or by setting the :attr:`.ModelAdmin.popup_response_template`
  69. attribute.
  70. :mod:`django.contrib.auth`
  71. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. * The default iteration count for the PBKDF2 password hasher is increased by
  73. 20%.
  74. * The :class:`~django.contrib.auth.views.LoginView` and
  75. :class:`~django.contrib.auth.views.LogoutView` class-based views supersede the
  76. deprecated ``login()`` and ``logout()`` function-based views.
  77. * The :class:`~django.contrib.auth.views.PasswordChangeView`,
  78. :class:`~django.contrib.auth.views.PasswordChangeDoneView`,
  79. :class:`~django.contrib.auth.views.PasswordResetView`,
  80. :class:`~django.contrib.auth.views.PasswordResetDoneView`,
  81. :class:`~django.contrib.auth.views.PasswordResetConfirmView`, and
  82. :class:`~django.contrib.auth.views.PasswordResetCompleteView` class-based
  83. views supersede the deprecated ``password_change()``,
  84. ``password_change_done()``, ``password_reset()``, ``password_reset_done()``,
  85. ``password_reset_confirm()``, and ``password_reset_complete()`` function-based
  86. views.
  87. * The new ``post_reset_login`` attribute for
  88. :class:`~django.contrib.auth.views.PasswordResetConfirmView` allows
  89. automatically logging in a user after a successful password reset.
  90. If you have multiple ``AUTHENTICATION_BACKENDS`` configured, use the
  91. ``post_reset_login_backend`` attribute to choose which one to use.
  92. * To avoid the possibility of leaking a password reset token via the HTTP
  93. Referer header (for example, if the reset page includes a reference to CSS or
  94. JavaScript hosted on another domain), the
  95. :class:`~django.contrib.auth.views.PasswordResetConfirmView` (but not the
  96. deprecated ``password_reset_confirm()`` function-based view) stores the token
  97. in a session and redirects to itself to present the password change form to
  98. the user without the token in the URL.
  99. * :func:`~django.contrib.auth.update_session_auth_hash` now rotates the session
  100. key to allow a password change to invalidate stolen session cookies.
  101. * The new ``success_url_allowed_hosts`` attribute for
  102. :class:`~django.contrib.auth.views.LoginView` and
  103. :class:`~django.contrib.auth.views.LogoutView` allows specifying a set of
  104. hosts that are safe for redirecting after login and logout.
  105. * Added password validators ``help_text`` to
  106. :class:`~django.contrib.auth.forms.UserCreationForm`.
  107. * The ``HttpRequest`` is now passed to :func:`~django.contrib.auth.authenticate`
  108. which in turn passes it to the authentication backend if it accepts a
  109. ``request`` argument.
  110. * The :func:`~django.contrib.auth.signals.user_login_failed` signal now
  111. receives a ``request`` argument.
  112. * :class:`~django.contrib.auth.forms.PasswordResetForm` supports custom user
  113. models that use an email field named something other than ``'email'``.
  114. Set :attr:`CustomUser.EMAIL_FIELD
  115. <django.contrib.auth.models.CustomUser.EMAIL_FIELD>` to the name of the field.
  116. * :func:`~django.contrib.auth.get_user_model` can now be called at import time,
  117. even in modules that define models.
  118. :mod:`django.contrib.contenttypes`
  119. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120. * When stale content types are detected in the
  121. :djadmin:`remove_stale_contenttypes` command, there's now a list of related
  122. objects such as ``auth.Permission``\s that will also be deleted. Previously,
  123. only the content types were listed (and this prompt was after ``migrate``
  124. rather than in a separate command).
  125. :mod:`django.contrib.gis`
  126. ~~~~~~~~~~~~~~~~~~~~~~~~~
  127. * The new :meth:`.GEOSGeometry.from_gml` and :meth:`.OGRGeometry.from_gml`
  128. methods allow creating geometries from GML.
  129. * Added support for the :lookup:`dwithin` lookup on SpatiaLite.
  130. * The :class:`~django.contrib.gis.db.models.functions.Area` function,
  131. :class:`~django.contrib.gis.db.models.functions.Distance` function, and
  132. distance lookups now work with geodetic coordinates on SpatiaLite.
  133. * The OpenLayers-based form widgets now use ``OpenLayers.js`` from
  134. ``https://cdnjs.cloudflare.com`` which is more suitable for production use
  135. than the the old ``http://openlayers.org`` source. They are also updated to
  136. use OpenLayers 3.
  137. * PostGIS migrations can now change field dimensions.
  138. * Added the ability to pass the `size`, `shape`, and `offset` parameter when
  139. creating :class:`~django.contrib.gis.gdal.GDALRaster` objects.
  140. * Added SpatiaLite support for the
  141. :class:`~django.contrib.gis.db.models.functions.IsValid` function,
  142. :class:`~django.contrib.gis.db.models.functions.MakeValid` function, and
  143. :lookup:`isvalid` lookup.
  144. * Added Oracle support for the
  145. :class:`~django.contrib.gis.db.models.functions.AsGML` function,
  146. :class:`~django.contrib.gis.db.models.functions.BoundingCircle` function,
  147. :class:`~django.contrib.gis.db.models.functions.IsValid` function, and
  148. :lookup:`isvalid` lookup.
  149. :mod:`django.contrib.postgres`
  150. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151. * The new ``distinct`` argument for
  152. :class:`~django.contrib.postgres.aggregates.StringAgg` determines if
  153. concatenated values will be distinct.
  154. * The new :class:`~django.contrib.postgres.indexes.GinIndex` and
  155. :class:`~django.contrib.postgres.indexes.BrinIndex` classes allow
  156. creating ``GIN`` and ``BRIN`` indexes in the database.
  157. * :class:`~django.contrib.postgres.fields.JSONField` accepts a new ``encoder``
  158. parameter to specify a custom class to encode data types not supported by the
  159. standard encoder.
  160. * The new :class:`~django.contrib.postgres.fields.CIText` mixin and
  161. :class:`~django.contrib.postgres.operations.CITextExtension` migration
  162. operation allow using PostgreSQL's ``citext`` extension for case-insensitive
  163. lookups. Three fields are provided: :class:`.CICharField`,
  164. :class:`.CIEmailField`, and :class:`.CITextField`.
  165. * The new :class:`~django.contrib.postgres.aggregates.JSONBAgg` allows
  166. aggregating values as a JSON array.
  167. * :class:`~django.contrib.postgres.fields.HStoreField` and
  168. :class:`~django.contrib.postgres.forms.HStoreField` allow storing null
  169. values.
  170. Cache
  171. ~~~~~
  172. * Memcached backends now pass the contents of :setting:`OPTIONS <CACHES-OPTIONS>`
  173. as keyword arguments to the client constructors, allowing for more advanced
  174. control of client behavior. See the :ref:`cache arguments <cache_arguments>`
  175. documentation for examples.
  176. * Memcached backends now allow defining multiple servers as a comma-delimited
  177. string in :setting:`LOCATION <CACHES-LOCATION>`, for convenience with
  178. third-party services that use such strings in environment variables.
  179. CSRF
  180. ~~~~
  181. * Added the :setting:`CSRF_USE_SESSIONS` setting to allow storing the CSRF
  182. token in the user's session rather than in a cookie.
  183. Database backends
  184. ~~~~~~~~~~~~~~~~~
  185. * Added the ``skip_locked`` argument to :meth:`.QuerySet.select_for_update()`
  186. on PostgreSQL 9.5+ and Oracle to execute queries with
  187. ``FOR UPDATE SKIP LOCKED``.
  188. * Added the :setting:`TEST['TEMPLATE'] <TEST_TEMPLATE>` setting to let
  189. PostgreSQL users specify a template for creating the test database.
  190. * :meth:`.QuerySet.iterator()` now uses :ref:`server-side cursors
  191. <psycopg2:server-side-cursors>` on PostgreSQL. This feature transfers some of
  192. the worker memory load (used to hold query results) to the database and might
  193. increase database memory usage.
  194. * Added MySQL support for the ``'isolation_level'`` option in
  195. :setting:`OPTIONS` to allow specifying the :ref:`transaction isolation level
  196. <mysql-isolation-level>`. To avoid possible data loss, it's recommended to
  197. switch from MySQL's default level, repeatable read, to read committed.
  198. * Added support for ``cx_Oracle`` 5.3.
  199. Email
  200. ~~~~~
  201. * Added the :setting:`EMAIL_USE_LOCALTIME` setting to allow sending SMTP date
  202. headers in the local time zone rather than in UTC.
  203. * ``EmailMessage.attach()`` and ``attach_file()`` now fall back to MIME type
  204. ``application/octet-stream`` when binary content that can't be decoded as
  205. UTF-8 is specified for a ``text/*`` attachment.
  206. File Storage
  207. ~~~~~~~~~~~~
  208. * To make it wrappable by :class:`io.TextIOWrapper`,
  209. :class:`~django.core.files.File` now has the ``readable()``, ``writable()``,
  210. and ``seekable()`` methods.
  211. Forms
  212. ~~~~~
  213. * The new :attr:`CharField.empty_value <django.forms.CharField.empty_value>`
  214. attribute allows specifying the Python value to use to represent "empty".
  215. * The new :meth:`Form.get_initial_for_field()
  216. <django.forms.Form.get_initial_for_field>` method returns initial data for a
  217. form field.
  218. Internationalization
  219. ~~~~~~~~~~~~~~~~~~~~
  220. * Number formatting and the :setting:`NUMBER_GROUPING` setting support
  221. non-uniform digit grouping.
  222. Management Commands
  223. ~~~~~~~~~~~~~~~~~~~
  224. * The new :option:`loaddata --exclude` option allows excluding models and apps
  225. while loading data from fixtures.
  226. * The new :option:`diffsettings --default` option allows specifying a settings
  227. module other than Django's default settings to compare against.
  228. * ``app_label``\s arguments now limit the :option:`showmigrations --plan`
  229. output.
  230. Migrations
  231. ~~~~~~~~~~
  232. * Added support for serialization of ``uuid.UUID`` objects.
  233. Models
  234. ~~~~~~
  235. * Added support for callable values in the ``defaults`` argument of
  236. :meth:`QuerySet.update_or_create()
  237. <django.db.models.query.QuerySet.update_or_create>` and
  238. :meth:`~django.db.models.query.QuerySet.get_or_create`.
  239. * :class:`~django.db.models.ImageField` now has a default
  240. :data:`~django.core.validators.validate_image_file_extension` validator.
  241. * Added support for time truncation to
  242. :class:`~django.db.models.functions.datetime.Trunc` functions.
  243. * Added the :class:`~django.db.models.functions.datetime.ExtractWeek` function
  244. to extract the week from :class:`~django.db.models.DateField` and
  245. :class:`~django.db.models.DateTimeField` and exposed it through the
  246. :lookup:`week` lookup.
  247. * Added the :class:`~django.db.models.functions.datetime.TruncTime` function
  248. to truncate :class:`~django.db.models.DateTimeField` to its time component
  249. and exposed it through the :lookup:`time` lookup.
  250. * Added support for expressions in :meth:`.QuerySet.values` and
  251. :meth:`~.QuerySet.values_list`.
  252. * Added support for query expressions on lookups that take multiple arguments,
  253. such as ``range``.
  254. * You can now use the ``unique=True`` option with
  255. :class:`~django.db.models.FileField`.
  256. * Added the ``nulls_first`` and ``nulls_last`` parameters to
  257. :class:`Expression.asc() <django.db.models.Expression.asc>` and
  258. :meth:`~django.db.models.Expression.desc` to control
  259. the ordering of null values.
  260. * The new ``F`` expression ``bitleftshift()`` and ``bitrightshift()`` methods
  261. allow :ref:`bitwise shift operations <using-f-expressions-in-filters>`.
  262. * Added :meth:`.QuerySet.union`, :meth:`~.QuerySet.intersection`, and
  263. :meth:`~.QuerySet.difference`.
  264. Requests and Responses
  265. ~~~~~~~~~~~~~~~~~~~~~~
  266. * Added :meth:`QueryDict.fromkeys() <django.http.QueryDict.fromkeys>`.
  267. * :class:`~django.middleware.common.CommonMiddleware` now sets the
  268. ``Content-Length`` response header for non-streaming responses.
  269. * Added the :setting:`SECURE_HSTS_PRELOAD` setting to allow appending the
  270. ``preload`` directive to the ``Strict-Transport-Security`` header.
  271. * :class:`~django.middleware.http.ConditionalGetMiddleware` now adds the
  272. ``ETag`` header to responses.
  273. Serialization
  274. ~~~~~~~~~~~~~
  275. * The new ``django.core.serializers.base.Serializer.stream_class`` attribute
  276. allows subclasses to customize the default stream.
  277. * The encoder used by the :ref:`JSON serializer <serialization-formats-json>`
  278. can now be customized by passing a ``cls`` keyword argument to the
  279. ``serializers.serialize()`` function.
  280. * :class:`~django.core.serializers.json.DjangoJSONEncoder` now serializes
  281. :class:`~datetime.timedelta` objects (used by
  282. :class:`~django.db.models.DurationField`).
  283. Templates
  284. ~~~~~~~~~
  285. * :meth:`~django.utils.safestring.mark_safe` can now be used as a decorator.
  286. * The :class:`~django.template.backends.jinja2.Jinja2` template backend now
  287. supports context processors by setting the ``'context_processors'`` option in
  288. :setting:`OPTIONS <TEMPLATES-OPTIONS>`.
  289. * The :ttag:`regroup` tag now returns ``namedtuple``\s instead of dictionaries
  290. so you can unpack the group object directly in a loop, e.g.
  291. ``{% for grouper, list in regrouped %}``.
  292. * Added a :ttag:`resetcycle` template tag to allow resetting the sequence of
  293. the :ttag:`cycle` template tag.
  294. * You can now specify specific directories for a particular
  295. :class:`filesystem.Loader <django.template.loaders.filesystem.Loader>`.
  296. Tests
  297. ~~~~~
  298. * Added :meth:`.DiscoverRunner.get_test_runner_kwargs` to allow customizing the
  299. keyword arguments passed to the test runner.
  300. * Added the :option:`test --debug-mode` option to help troubleshoot test
  301. failures by setting the :setting:`DEBUG` setting to ``True``.
  302. * The new :func:`django.test.utils.setup_databases` (moved from
  303. ``django.test.runner``) and :func:`~django.test.utils.teardown_databases`
  304. functions make it easier to build custom test runners.
  305. * Added support for :meth:`python:unittest.TestCase.subTest`’s when using the
  306. :option:`test --parallel` option.
  307. * ``DiscoverRunner`` now runs the system checks at the start of a test run.
  308. Override the :meth:`.DiscoverRunner.run_checks` method if you want to disable
  309. that.
  310. Validators
  311. ~~~~~~~~~~
  312. * Added :class:`~django.core.validators.FileExtensionValidator` to validate
  313. file extensions and
  314. :data:`~django.core.validators.validate_image_file_extension` to validate
  315. image files.
  316. .. _backwards-incompatible-1.11:
  317. Backwards incompatible changes in 1.11
  318. ======================================
  319. :mod:`django.contrib.gis`
  320. -------------------------
  321. * To simplify the codebase and because it's easier to install than when
  322. ``contrib.gis`` was first released, :ref:`gdalbuild` is now a required
  323. dependency for GeoDjango. In older versions, it's only required for SQLite.
  324. * ``contrib.gis.maps`` is removed as it interfaces with a retired version of
  325. the Google Maps API and seems to be unmaintained. If you're using it, `let
  326. us know <https://code.djangoproject.com/ticket/14284>`_.
  327. * The ``GEOSGeometry`` equality operator now also compares SRID.
  328. * The OpenLayers-based form widgets now use OpenLayers 3, and the
  329. ``gis/openlayers.html`` and ``gis/openlayers-osm.html`` templates have been
  330. updated. Check your project if you subclass these widgets or extend the
  331. templates. Also, the new widgets work a bit differently than the old ones.
  332. Instead of using a toolbar in the widget, you click to draw, click and drag
  333. to move the map, and click and drag a point/vertex/corner to move it.
  334. * Support for SpatiaLite < 4.0 is dropped.
  335. * Support for GDAL 1.7 and 1.8 is dropped.
  336. :mod:`django.contrib.staticfiles`
  337. ---------------------------------
  338. * ``collectstatic`` may now fail during post-processing when using a hashed
  339. static files storage if a reference loop exists (e.g. ``'foo.css'``
  340. references ``'bar.css'`` which itself references ``'foo.css'``) or if the
  341. chain of files referencing other files is too deep to resolve in several
  342. passes. In the latter case, increase the number of passes using
  343. :attr:`.ManifestStaticFilesStorage.max_post_process_passes`.
  344. * When using ``ManifestStaticFilesStorage``, static files not found in the
  345. manifest at runtime now raise a ``ValueError`` instead of returning an
  346. unchanged path. You can revert to the old behavior by setting
  347. :attr:`.ManifestStaticFilesStorage.manifest_strict` to ``False``.
  348. Database backend API
  349. --------------------
  350. * The ``DatabaseOperations.time_trunc_sql()`` method is added to support
  351. ``TimeField`` truncation. It accepts a ``lookup_type`` and ``field_name``
  352. arguments and returns the appropriate SQL to truncate the given time field
  353. ``field_name`` to a time object with only the given specificity. The
  354. ``lookup_type`` argument can be either ``'hour'``, ``'minute'``, or
  355. ``'second'``.
  356. * The ``DatabaseOperations.datetime_cast_time_sql()`` method is added to
  357. support the :lookup:`time` lookup. It accepts a ``field_name`` and ``tzname``
  358. arguments and returns the SQL necessary to cast a datetime value to time value.
  359. * To enable ``FOR UPDATE SKIP LOCKED`` support, set
  360. ``DatabaseFeatures.has_select_for_update_skip_locked = True``.
  361. * The new ``DatabaseFeatures.supports_index_column_ordering`` attribute
  362. specifies if a database allows defining ordering for columns in indexes. The
  363. default value is ``True`` and the ``DatabaseIntrospection.get_constraints()``
  364. method should include an ``'orders'`` key in each of the returned
  365. dictionaries with a list of ``'ASC'`` and/or ``'DESC'`` values corresponding
  366. to the the ordering of each column in the index.
  367. * :djadmin:`inspectdb` no longer calls ``DatabaseIntrospection.get_indexes()``
  368. which is deprecated. Custom database backends should ensure all types of
  369. indexes are returned by ``DatabaseIntrospection.get_constraints()``.
  370. * Renamed the ``ignores_quoted_identifier_case`` feature to
  371. ``ignores_table_name_case`` to more accurately reflect how it is used.
  372. * The ``name`` keyword argument is added to the
  373. ``DatabaseWrapper.create_cursor(self, name=None)`` method to allow usage of
  374. server-side cursors on backends that support it.
  375. Dropped support for PostgreSQL 9.2 and PostGIS 2.0
  376. --------------------------------------------------
  377. Upstream support for PostgreSQL 9.2 ends in September 2017. As a consequence,
  378. Django 1.11 sets PostgreSQL 9.3 as the minimum version it officially supports.
  379. Support for PostGIS 2.0 is also removed as PostgreSQL 9.2 is the last version
  380. to support it.
  381. Also, the minimum supported version of psycopg2 is increased from 2.4.5 to
  382. 2.5.4.
  383. ``LiveServerTestCase`` binds to port zero
  384. -----------------------------------------
  385. Rather than taking a port range and iterating to find a free port,
  386. ``LiveServerTestCase`` binds to port zero and relies on the operating system
  387. to assign a free port. The ``DJANGO_LIVE_TEST_SERVER_ADDRESS`` environment
  388. variable is no longer used, and as it's also no longer used, the
  389. ``manage.py test --liveserver`` option is removed.
  390. Protection against insecure redirects in :mod:`django.contrib.auth` and ``i18n`` views
  391. --------------------------------------------------------------------------------------
  392. ``LoginView``, ``LogoutView`` (and the deprecated function-based equivalents),
  393. and :func:`~django.views.i18n.set_language` protect users from being redirected
  394. to non-HTTPS ``next`` URLs when the app is running over HTTPS.
  395. ``QuerySet.get_or_create()`` and ``update_or_create()`` validate arguments
  396. --------------------------------------------------------------------------
  397. To prevent typos from passing silently,
  398. :meth:`~django.db.models.query.QuerySet.get_or_create` and
  399. :meth:`~django.db.models.query.QuerySet.update_or_create` check that their
  400. arguments are model fields. This should be backwards-incompatible only in the
  401. fact that it might expose a bug in your project.
  402. ``pytz`` is a required dependency and support for ``settings.TIME_ZONE = None`` is removed
  403. ------------------------------------------------------------------------------------------
  404. To simplify Django's timezone handling, ``pytz`` is now a required dependency.
  405. It's automatically installed along with Django.
  406. Support for ``settings.TIME_ZONE = None`` is removed as the behavior isn't
  407. commonly used and is questionably useful. If you want to automatically detect
  408. the timezone based on the system timezone, you can use `tzlocal
  409. <https://pypi.python.org/pypi/tzlocal>`_::
  410. from tzlocal import get_localzone
  411. TIME_ZONE = get_localzone().zone
  412. This works similar to ``settings.TIME_ZONE = None`` except that it also sets
  413. ``os.environ['TZ']``. `Let us know
  414. <https://groups.google.com/d/topic/django-developers/OAV3FChfuPM/discussion>`__
  415. if there's a use case where you find you can't adapt your code to set a
  416. ``TIME_ZONE``.
  417. HTML changes in admin templates
  418. -------------------------------
  419. ``<p class="help">`` is replaced with a ``<div>`` tag to allow including lists
  420. inside help text.
  421. Read-only fields are wrapped in ``<div class="readonly">...</div>`` instead of
  422. ``<p>...</p>`` to allow any kind of HTML as the field's content.
  423. .. _template-widget-incompatibilities-1-11:
  424. Changes due to the introduction of template-based widget rendering
  425. ------------------------------------------------------------------
  426. Some undocumented classes in ``django.forms.widgets`` are removed:
  427. * ``SubWidget``
  428. * ``RendererMixin``, ``ChoiceFieldRenderer``, ``RadioFieldRenderer``,
  429. ``CheckboxFieldRenderer``
  430. * ``ChoiceInput``, ``RadioChoiceInput``, ``CheckboxChoiceInput``
  431. The ``Widget.format_output()`` method is removed. Use a custom widget template
  432. instead.
  433. Some widget values, such as ``<select>`` options, are now localized if
  434. ``settings.USE_L10N=True``. You could revert to the old behavior with custom
  435. widget templates that uses the :ttag:`localize` template tag to turn off
  436. localization.
  437. ``django.Template.render()`` prohibits non-dict context
  438. -------------------------------------------------------
  439. For compatibility with multiple template engines, ``django.Template.render()``
  440. must receive a dictionary of context rather than ``Context`` or
  441. ``RequestContext``. If you were passing either of the two classes, pass a
  442. dictionary instead -- doing so is backwards-compatible with older versions of
  443. Django.
  444. Model state changes in migration operations
  445. -------------------------------------------
  446. To improve the speed of applying migrations, rendering of related models is
  447. delayed until an operation that needs them (e.g. ``RunPython``). If you have a
  448. custom operation that works with model classes or model instances from the
  449. ``from_state`` argument in ``database_forwards()`` or ``database_backwards()``,
  450. you must render model states using the ``clear_delayed_apps_cache()`` method as
  451. described in :ref:`writing your own migration operation
  452. <writing-your-own-migration-operation>`.
  453. Miscellaneous
  454. -------------
  455. * If no items in the feed have a ``pubdate`` or ``updateddate`` attribute,
  456. :meth:`SyndicationFeed.latest_post_date()
  457. <django.utils.feedgenerator.SyndicationFeed.latest_post_date>` now returns
  458. the current UTC date/time, instead of a datetime without any timezone
  459. information.
  460. * CSRF failures are logged to the ``django.security.csrf`` logger instead of
  461. ``django.request``.
  462. * :setting:`ALLOWED_HOSTS` validation is no longer disabled when running tests.
  463. If your application includes tests with custom host names, you must include
  464. those host names in :setting:`ALLOWED_HOSTS`. See
  465. :ref:`topics-testing-advanced-multiple-hosts`.
  466. * Using a foreign key's id (e.g. ``'field_id'``) in ``ModelAdmin.list_display``
  467. displays the related object's ID. Remove the ``_id`` suffix if you want the
  468. old behavior of the string representation of the object.
  469. * In model forms, :class:`~django.db.models.CharField` with ``null=True`` now
  470. saves ``NULL`` for blank values instead of empty strings.
  471. * On Oracle, :meth:`Model.validate_unique()
  472. <django.db.models.Model.validate_unique>` no longer checks empty strings for
  473. uniqueness as the database interprets the value as ``NULL``.
  474. * If you subclass :class:`.AbstractUser` and override ``clean()``, be sure it
  475. calls ``super()``. :meth:`.BaseUserManager.normalize_email` is called in a
  476. new :meth:`.AbstractUser.clean` method so that normalization is applied in
  477. cases like model form validation.
  478. * ``EmailField`` and ``URLField`` no longer accept the ``strip`` keyword
  479. argument. Remove it because it doesn't have an effect in older versions of
  480. Django as these fields always strip whitespace.
  481. * The ``checked`` and ``selected`` attribute rendered by form widgets now uses
  482. HTML5 boolean syntax rather than XHTML's ``checked='checked'`` and
  483. ``selected='selected'``.
  484. * :meth:`RelatedManager.add()
  485. <django.db.models.fields.related.RelatedManager.add>`,
  486. :meth:`~django.db.models.fields.related.RelatedManager.remove`,
  487. :meth:`~django.db.models.fields.related.RelatedManager.clear`, and
  488. :meth:`~django.db.models.fields.related.RelatedManager.set` now
  489. clear the ``prefetch_related()`` cache.
  490. * To prevent possible loss of saved settings,
  491. :func:`~django.test.utils.setup_test_environment` now raises an exception if
  492. called a second time before calling
  493. :func:`~django.test.utils.teardown_test_environment`.
  494. * The undocumented ``DateTimeAwareJSONEncoder`` alias for
  495. :class:`~django.core.serializers.json.DjangoJSONEncoder` (renamed in Django
  496. 1.0) is removed.
  497. * The :class:`cached template loader <django.template.loaders.cached.Loader>`
  498. is now enabled if :setting:`DEBUG` is ``False`` and
  499. :setting:`OPTIONS['loaders'] <TEMPLATES-OPTIONS>` isn't specified. This could
  500. be backwards-incompatible if you have some :ref:`template tags that aren't
  501. thread safe <template_tag_thread_safety>`.
  502. * The prompt for stale content type deletion no longer occurs after running the
  503. ``migrate`` command. Use the new :djadmin:`remove_stale_contenttypes` command
  504. instead.
  505. * The admin's widget for ``IntegerField`` uses ``type="number"`` rather than
  506. ``type="text"``.
  507. * Conditional HTTP headers are now parsed and compared according to the
  508. :rfc:`7232` Conditional Requests specification rather than the older
  509. :rfc:`2616`.
  510. * :func:`~django.utils.cache.patch_response_headers` no longer adds a
  511. ``Last-Modified`` header. According to the :rfc:`7234#section-4.2.2`, this
  512. header is useless alongside other caching headers that provide an explicit
  513. expiration time, e.g. ``Expires`` or ``Cache-Control``.
  514. :class:`~django.middleware.cache.UpdateCacheMiddleware` and
  515. :func:`~django.utils.cache.add_never_cache_headers` call
  516. ``patch_response_headers()`` and therefore are also affected by this change.
  517. * In the admin templates, ``<p class="help">`` is replaced with a ``<div>`` tag
  518. to allow including lists inside help text.
  519. * :class:`~django.middleware.http.ConditionalGetMiddleware` no longer sets the
  520. ``Date`` header as Web servers set that header. It also no longer sets the
  521. ``Content-Length`` header as this is now done by
  522. :class:`~django.middleware.common.CommonMiddleware`.
  523. * :meth:`~django.apps.AppConfig.get_model` and
  524. :meth:`~django.apps.AppConfig.get_models` now raise
  525. :exc:`~django.core.exceptions.AppRegistryNotReady` if they're called before
  526. models of all applications have been loaded. Previously they only required
  527. the target application's models to be loaded and thus could return models
  528. without all their relations set up. If you need the old behavior of
  529. ``get_model()``, set the ``require_ready`` argument to ``False``.
  530. * The unused ``BaseCommand.can_import_settings`` attribute is removed.
  531. * The undocumented ``django.utils.functional.lazy_property`` is removed.
  532. * For consistency with non-multipart requests, ``MultiPartParser.parse()`` now
  533. leaves ``request.POST`` immutable. If you're modifying that ``QueryDict``,
  534. you must now first copy it, e.g. ``request.POST.copy()``.
  535. * Support for ``cx_Oracle`` < 5.2 is removed.
  536. * Support for IPython < 1.0 is removed from the ``shell`` command.
  537. .. _deprecated-features-1.11:
  538. Features deprecated in 1.11
  539. ===========================
  540. ``models.permalink()`` decorator
  541. --------------------------------
  542. Use :func:`django.urls.reverse` instead. For example::
  543. from django.db import models
  544. class MyModel(models.Model):
  545. ...
  546. @models.permalink
  547. def url(self):
  548. return ('guitarist_detail', [self.slug])
  549. becomes::
  550. from django.db import models
  551. from django.urls import reverse
  552. class MyModel(models.Model):
  553. ...
  554. def url(self):
  555. return reverse('guitarist_detail', args=[self.slug])
  556. Miscellaneous
  557. -------------
  558. * ``contrib.auth``’s ``login()`` and ``logout()`` function-based views are
  559. deprecated in favor of new class-based views
  560. :class:`~django.contrib.auth.views.LoginView` and
  561. :class:`~django.contrib.auth.views.LogoutView`.
  562. * The unused ``extra_context`` parameter of
  563. ``contrib.auth.views.logout_then_login()`` is deprecated.
  564. * ``contrib.auth``’s ``password_change()``, ``password_change_done()``,
  565. ``password_reset()``, ``password_reset_done()``, ``password_reset_confirm()``,
  566. and ``password_reset_complete()`` function-based views are deprecated in favor
  567. of new class-based views
  568. :class:`~django.contrib.auth.views.PasswordChangeView`,
  569. :class:`~django.contrib.auth.views.PasswordChangeDoneView`,
  570. :class:`~django.contrib.auth.views.PasswordResetView`,
  571. :class:`~django.contrib.auth.views.PasswordResetDoneView`,
  572. :class:`~django.contrib.auth.views.PasswordResetConfirmView`, and
  573. :class:`~django.contrib.auth.views.PasswordResetCompleteView`.
  574. * ``django.test.runner.setup_databases()`` is moved to
  575. :func:`django.test.utils.setup_databases`. The old location is deprecated.
  576. * ``django.utils.translation.string_concat()`` is deprecated in
  577. favor of :func:`django.utils.text.format_lazy`. ``string_concat(*strings)``
  578. can be replaced by ``format_lazy('{}' * len(strings), *strings)``.
  579. * For the ``PyLibMCCache`` cache backend, passing ``pylibmc`` behavior settings
  580. as top-level attributes of ``OPTIONS`` is deprecated. Set them under a
  581. ``behaviors`` key within ``OPTIONS`` instead.
  582. * The ``host`` parameter of ``django.utils.http.is_safe_url()`` is deprecated
  583. in favor of the new ``allowed_hosts`` parameter.
  584. * Silencing exceptions raised while rendering the
  585. :ttag:`{% include %} <include>` template tag is deprecated as the behavior is
  586. often more confusing than helpful. In Django 2.1, the exception will be
  587. raised.
  588. * ``DatabaseIntrospection.get_indexes()`` is deprecated in favor of
  589. ``DatabaseIntrospection.get_constraints()``.
  590. * :func:`~django.contrib.auth.authenticate` now passes a ``request`` argument
  591. to the ``authenticate()`` method of authentication backends. Support for
  592. methods that don't accept ``request`` as the first positional argument will
  593. be removed in Django 2.1.
  594. * The ``USE_ETAGS`` setting is deprecated in favor of
  595. :class:`~django.middleware.http.ConditionalGetMiddleware` which now adds the
  596. ``ETag`` header to responses regardless of the setting. ``CommonMiddleware``
  597. and ``django.utils.cache.patch_response_headers()`` will no longer set ETags
  598. when the deprecation ends.
  599. * ``Model._meta.has_auto_field`` is deprecated in favor of checking if
  600. ``Model._meta.auto_field is not None``.
  601. * Using regular expression groups with ``iLmsu#`` in ``url()`` is deprecated.
  602. The only group that's useful is ``(?i)`` for case-insensitive URLs, however,
  603. case-insensitive URLs aren't a good practice because they create multiple
  604. entries for search engines, for example. An alternative solution could be to
  605. create a :data:`~django.conf.urls.handler404` that looks for uppercase
  606. characters in the URL and redirects to a lowercase equivalent.
  607. * The ``renderer`` argument is added to the :meth:`Widget.render()
  608. <django.forms.Widget.render>` method. Methods that don't accept that argument
  609. will work through a deprecation period.