1.11.txt 36 KB

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