1.11.txt 36 KB

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