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