1.11.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. =============================================
  2. Django 1.11 release notes - UNDER DEVELOPMENT
  3. =============================================
  4. Welcome to Django 1.11!
  5. These release notes cover the :ref:`new features <whats-new-1.11>`, as well as
  6. some :ref:`backwards incompatible changes <backwards-incompatible-1.11>` you'll
  7. want to be aware of when upgrading from Django 1.10 or older versions. We've
  8. :ref:`begun the deprecation process for some features
  9. <deprecated-features-1.11>`.
  10. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  11. project.
  12. Django 1.11 is designated as a :term:`long-term support release`. It will
  13. receive security updates for at least three years after its release. Support
  14. for the previous LTS, Django 1.8, will end in April 2018.
  15. Python compatibility
  16. ====================
  17. Like Django 1.10, Django 1.11 requires Python 2.7, 3.4, or 3.5. We **highly
  18. recommend** and only officially support the latest release of each series.
  19. The Django 1.11.x series is the last to support Python 2. The next major
  20. release, Django 2.0, will only support Python 3.5+.
  21. Deprecating warnings are no longer loud by default
  22. ==================================================
  23. Unlike older versions of Django, Django's own deprecation warnings are no
  24. longer displayed by default. This is consistent with Python's default behavior.
  25. This change allows third-party apps to support both Django 1.11 LTS and Django
  26. 1.8 LTS without having to add code to avoid deprecation warnings.
  27. Following the release of Django 2.0, we suggest that third-party app authors
  28. drop support for all versions of Django prior to 1.11. At that time, you should
  29. be able run your package's tests using ``python -Wd`` so that deprecation
  30. warnings do appear. After making the deprecation warning fixes, your app should
  31. be compatible with Django 2.0.
  32. .. _whats-new-1.11:
  33. What's new in Django 1.11
  34. =========================
  35. Class-based model indexes
  36. -------------------------
  37. The new :mod:`django.db.models.indexes` module contains classes which ease
  38. creating database indexes. Indexes are added to models using the
  39. :attr:`Meta.indexes <django.db.models.Options.indexes>` option.
  40. The :class:`~django.db.models.Index` class creates a b-tree index, as if you
  41. used :attr:`~django.db.models.Field.db_index` on the model field or
  42. :attr:`~django.db.models.Options.index_together` on the model ``Meta`` class.
  43. It can be subclassed to support different index types, such as
  44. :class:`~django.contrib.postgres.indexes.GinIndex`. It also allows defining the
  45. order (ASC/DESC) for the columns of the index.
  46. Minor features
  47. --------------
  48. :mod:`django.contrib.admin`
  49. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. * :attr:`.ModelAdmin.date_hierarchy` can now reference fields across relations.
  51. :mod:`django.contrib.admindocs`
  52. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  53. * ...
  54. :mod:`django.contrib.auth`
  55. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. * The default iteration count for the PBKDF2 password hasher is increased by
  57. 20%.
  58. * The :class:`~django.contrib.auth.views.LoginView` and
  59. :class:`~django.contrib.auth.views.LogoutView` class-based views supersede the
  60. deprecated ``login()`` and ``logout()`` function-based views.
  61. * The :class:`~django.contrib.auth.views.PasswordChangeView`,
  62. :class:`~django.contrib.auth.views.PasswordChangeDoneView`,
  63. :class:`~django.contrib.auth.views.PasswordResetView`,
  64. :class:`~django.contrib.auth.views.PasswordResetDoneView`,
  65. :class:`~django.contrib.auth.views.PasswordResetConfirmView`, and
  66. :class:`~django.contrib.auth.views.PasswordResetCompleteView` class-based
  67. views supersede the deprecated ``password_change()``,
  68. ``password_change_done()``, ``password_reset()``, ``password_reset_done()``,
  69. ``password_reset_confirm()``, and ``password_reset_complete()`` function-based
  70. views.
  71. * The new ``post_reset_login`` attribute for
  72. :class:`~django.contrib.auth.views.PasswordResetConfirmView` allows
  73. automatically logging in a user after a successful password reset.
  74. * :func:`~django.contrib.auth.update_session_auth_hash` now rotates the session
  75. key to allow a password change to invalidate stolen session cookies.
  76. * The new ``success_url_allowed_hosts`` attribute for
  77. :class:`~django.contrib.auth.views.LoginView` and
  78. :class:`~django.contrib.auth.views.LogoutView` allows specifying a set of
  79. hosts that are safe for redirecting after login and logout.
  80. :mod:`django.contrib.contenttypes`
  81. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. * When stale content types are detected in the
  83. :djadmin:`remove_stale_contenttypes` command, there's now a list of related
  84. objects such as ``auth.Permission``\s that will also be deleted. Previously,
  85. only the content types were listed (and this prompt was after ``migrate``
  86. rather than in a separate command).
  87. :mod:`django.contrib.gis`
  88. ~~~~~~~~~~~~~~~~~~~~~~~~~
  89. * The new :meth:`.GEOSGeometry.from_gml` and :meth:`.OGRGeometry.from_gml`
  90. methods allow creating geometries from GML.
  91. * Added support for the :lookup:`dwithin` lookup on SpatiaLite.
  92. * The OpenLayers-based form widgets now use ``OpenLayers.js`` from
  93. ``https://cdnjs.cloudflare.com`` which is more suitable for production use
  94. than the the old ``http://openlayers.org`` source.
  95. :mod:`django.contrib.messages`
  96. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  97. * ...
  98. :mod:`django.contrib.postgres`
  99. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  100. * The new ``distinct`` argument for
  101. :class:`~django.contrib.postgres.aggregates.StringAgg` determines if
  102. concatenated values will be distinct.
  103. * The new :class:`~django.contrib.postgres.indexes.GinIndex` class allows
  104. creating gin indexes in the database.
  105. * :class:`~django.contrib.postgres.fields.JSONField` accepts a new ``encoder``
  106. parameter to specify a custom class to encode data types not supported by the
  107. standard encoder.
  108. :mod:`django.contrib.redirects`
  109. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110. * ...
  111. :mod:`django.contrib.sessions`
  112. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  113. * ...
  114. :mod:`django.contrib.sitemaps`
  115. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  116. * ...
  117. :mod:`django.contrib.sites`
  118. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  119. * ...
  120. :mod:`django.contrib.staticfiles`
  121. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122. * ...
  123. :mod:`django.contrib.syndication`
  124. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  125. * ...
  126. Cache
  127. ~~~~~
  128. * Memcached backends now pass the contents of :setting:`OPTIONS <CACHES-OPTIONS>`
  129. as keyword arguments to the client constructors, allowing for more advanced
  130. control of client behavior. See the :ref:`cache arguments <cache_arguments>`
  131. documentation for examples.
  132. * Memcached backends now allow defining multiple servers as a comma-delimited
  133. string in :setting:`LOCATION <CACHES-LOCATION>`, for convenience with
  134. third-party services that use such strings in environment variables.
  135. CSRF
  136. ~~~~
  137. * ...
  138. Database backends
  139. ~~~~~~~~~~~~~~~~~
  140. * Added the ``skip_locked`` argument to :meth:`.QuerySet.select_for_update()`
  141. on PostgreSQL 9.5+ and Oracle to execute queries with
  142. ``FOR UPDATE SKIP LOCKED``.
  143. * Added the :setting:`TEST['TEMPLATE'] <TEST_TEMPLATE>` setting to let
  144. PostgreSQL users specify a template for creating the test database.
  145. Email
  146. ~~~~~
  147. * Added the :setting:`EMAIL_USE_LOCALTIME` setting to allow sending SMTP date
  148. headers in the local time zone rather than in UTC.
  149. * ``EmailMessage.attach()`` and ``attach_file()`` now fall back to MIME type
  150. ``application/octet-stream`` when binary content that can't be decoded as
  151. UTF-8 is specified for a ``text/*`` attachment.
  152. File Storage
  153. ~~~~~~~~~~~~
  154. * To make it wrappable by :class:`io.TextIOWrapper`,
  155. :class:`~django.core.files.File` now has the ``readable()``, ``writable()``,
  156. and ``seekable()`` methods.
  157. File Uploads
  158. ~~~~~~~~~~~~
  159. * ...
  160. Forms
  161. ~~~~~
  162. * The new :attr:`CharField.empty_value <django.forms.CharField.empty_value>`
  163. attribute allows specifying the Python value to use to represent "empty".
  164. * The new :meth:`Form.get_initial_for_field()
  165. <django.forms.Form.get_initial_for_field>` method returns initial data for a
  166. form field.
  167. Generic Views
  168. ~~~~~~~~~~~~~
  169. * ...
  170. Internationalization
  171. ~~~~~~~~~~~~~~~~~~~~
  172. * Number formatting and the :setting:`NUMBER_GROUPING` setting support
  173. non-uniform digit grouping.
  174. Management Commands
  175. ~~~~~~~~~~~~~~~~~~~
  176. * The new :option:`loaddata --exclude` option allows excluding models and apps
  177. while loading data from fixtures.
  178. Migrations
  179. ~~~~~~~~~~
  180. * ...
  181. Models
  182. ~~~~~~
  183. * Added support for callable values in the ``defaults`` argument of
  184. :meth:`QuerySet.update_or_create()
  185. <django.db.models.query.QuerySet.update_or_create>` and
  186. :meth:`~django.db.models.query.QuerySet.get_or_create`.
  187. * :class:`~django.db.models.ImageField` now has a default
  188. :data:`~django.core.validators.validate_image_file_extension` validator.
  189. * Added support for time truncation to
  190. :class:`~django.db.models.functions.datetime.Trunc` functions.
  191. * Added the :class:`~django.db.models.functions.datetime.TruncTime` function
  192. to truncate :class:`~django.db.models.DateTimeField` to its time component
  193. and exposed it through the :lookup:`time` lookup.
  194. * Added support for expressions in :meth:`.QuerySet.values` and
  195. :meth:`~.QuerySet.values_list`.
  196. * Added support for query expressions on lookups that take multiple arguments,
  197. such as ``range``.
  198. Requests and Responses
  199. ~~~~~~~~~~~~~~~~~~~~~~
  200. * Added :meth:`QueryDict.fromkeys() <django.http.QueryDict.fromkeys>`.
  201. * :class:`~django.middleware.common.CommonMiddleware` now sets the
  202. ``Content-Length`` response header for non-streaming responses.
  203. * Added the :setting:`SECURE_HSTS_PRELOAD` setting to allow appending the
  204. ``preload`` directive to the ``Strict-Transport-Security`` header.
  205. Serialization
  206. ~~~~~~~~~~~~~
  207. * The new ``django.core.serializers.base.Serializer.stream_class`` attribute
  208. allows subclasses to customize the default stream.
  209. * The encoder used by the :ref:`JSON serializer <serialization-formats-json>`
  210. can now be customized by passing a ``cls`` keyword argument to the
  211. ``serializers.serialize()`` function.
  212. * :class:`~django.core.serializers.json.DjangoJSONEncoder` now serializes
  213. :class:`~datetime.timedelta` objects (used by
  214. :class:`~django.db.models.DurationField`).
  215. Signals
  216. ~~~~~~~
  217. * ...
  218. Templates
  219. ~~~~~~~~~
  220. * :meth:`~django.utils.safestring.mark_safe` can now be used as a decorator.
  221. * The :class:`~django.template.backends.jinja2.Jinja2` template backend now
  222. supports context processors by setting the ``'context_processors'`` option in
  223. :setting:`OPTIONS <TEMPLATES-OPTIONS>`.
  224. * The :ttag:`regroup` tag now returns ``namedtuple``\s instead of dictionaries
  225. so you can unpack the group object directly in a loop, e.g.
  226. ``{% for grouper, list in regrouped %}``.
  227. * Added a :ttag:`resetcycle` template tag to allow resetting the sequence of
  228. the :ttag:`cycle` template tag.
  229. Tests
  230. ~~~~~
  231. * Added :meth:`.DiscoverRunner.get_test_runner_kwargs` to allow customizing the
  232. keyword arguments passed to the test runner.
  233. * Added the :option:`test --debug-mode` option to help troubleshoot test
  234. failures by setting the :setting:`DEBUG` setting to ``True``.
  235. * The new :func:`django.test.utils.setup_databases` (moved from
  236. ``django.test.runner``) and :func:`~django.test.utils.teardown_databases`
  237. functions make it easier to build custom test runners.
  238. * Added support for :meth:`python:unittest.TestCase.subTest`’s when using the
  239. :option:`test --parallel` option.
  240. URLs
  241. ~~~~
  242. * ...
  243. Validators
  244. ~~~~~~~~~~
  245. * Added :class:`~django.core.validators.FileExtensionValidator` to validate
  246. file extensions and
  247. :data:`~django.core.validators.validate_image_file_extension` to validate
  248. image files.
  249. .. _backwards-incompatible-1.11:
  250. Backwards incompatible changes in 1.11
  251. ======================================
  252. :mod:`django.contrib.gis`
  253. -------------------------
  254. * To simplify the codebase and because it's easier to install than when
  255. ``contrib.gis`` was first released, :ref:`gdalbuild` is now a required
  256. dependency for GeoDjango. In older versions, it's only required for SQLite.
  257. Database backend API
  258. --------------------
  259. * The ``DatabaseOperations.time_trunc_sql()`` method is added to support
  260. ``TimeField`` truncation. It accepts a ``lookup_type`` and ``field_name``
  261. arguments and returns the appropriate SQL to truncate the given time field
  262. ``field_name`` to a time object with only the given specificity. The
  263. ``lookup_type`` argument can be either ``'hour'``, ``'minute'``, or
  264. ``'second'``.
  265. * The ``DatabaseOperations.datetime_cast_time_sql()`` method is added to
  266. support the :lookup:`time` lookup. It accepts a ``field_name`` and ``tzname``
  267. arguments and returns the SQL necessary to cast a datetime value to time value.
  268. * To enable ``FOR UPDATE SKIP LOCKED`` support, set
  269. ``DatabaseFeatures.has_select_for_update_skip_locked = True``.
  270. * The new ``DatabaseFeatures.supports_index_column_ordering`` attribute
  271. specifies if a database allows defining ordering for columns in indexes. The
  272. default value is ``True`` and the ``DatabaseIntrospection.get_constraints()``
  273. method should include an ``'orders'`` key in each of the returned
  274. dictionaries with a list of ``'ASC'`` and/or ``'DESC'`` values corresponding
  275. to the the ordering of each column in the index.
  276. Dropped support for PostgreSQL 9.2 and PostGIS 2.0
  277. --------------------------------------------------
  278. Upstream support for PostgreSQL 9.2 ends in September 2017. As a consequence,
  279. Django 1.11 sets PostgreSQL 9.3 as the minimum version it officially supports.
  280. Support for PostGIS 2.0 is also removed as PostgreSQL 9.2 is the last version
  281. to support it.
  282. ``LiveServerTestCase`` binds to port zero
  283. -----------------------------------------
  284. Rather than taking a port range and iterating to find a free port,
  285. ``LiveServerTestCase`` binds to port zero and relies on the operating system
  286. to assign a free port. The ``DJANGO_LIVE_TEST_SERVER_ADDRESS`` environment
  287. variable is no longer used, and as it's also no longer used, the
  288. ``manage.py test --liveserver`` option is removed.
  289. Protection against insecure redirects in :mod:`django.contrib.auth` and ``i18n`` views
  290. --------------------------------------------------------------------------------------
  291. ``LoginView``, ``LogoutView`` (and the deprecated function-based equivalents),
  292. and :func:`~django.views.i18n.set_language` protect users from being redirected
  293. to non-HTTPS ``next`` URLs when the app is running over HTTPS.
  294. Miscellaneous
  295. -------------
  296. * If no items in the feed have a ``pubdate`` or ``updateddate`` attribute,
  297. :meth:`SyndicationFeed.latest_post_date()
  298. <django.utils.feedgenerator.SyndicationFeed.latest_post_date>` now returns
  299. the current UTC date/time, instead of a datetime without any timezone
  300. information.
  301. * Support for SpatiaLite < 4.0 is dropped.
  302. * CSRF failures are logged to the ``django.security.csrf`` logger instead of
  303. ``django.request``.
  304. * :setting:`ALLOWED_HOSTS` validation is no longer disabled when running tests.
  305. If your application includes tests with custom host names, you must include
  306. those host names in :setting:`ALLOWED_HOSTS`. See
  307. :ref:`topics-testing-advanced-multiple-hosts`.
  308. * Using a foreign key's id (e.g. ``'field_id'``) in ``ModelAdmin.list_display``
  309. displays the related object's ID. Remove the ``_id`` suffix if you want the
  310. old behavior of the string representation of the object.
  311. * In model forms, :class:`~django.db.models.CharField` with ``null=True`` now
  312. saves ``NULL`` for blank values instead of empty strings.
  313. * On Oracle, :meth:`Model.validate_unique()
  314. <django.db.models.Model.validate_unique>` no longer checks empty strings for
  315. uniqueness as the database interprets the value as ``NULL``.
  316. * If you subclass :class:`.AbstractUser` and override ``clean()``, be sure it
  317. calls ``super()``. :meth:`.BaseUserManager.normalize_email` is called in a
  318. new :meth:`.AbstractUser.clean` method so that normalization is applied in
  319. cases like model form validation.
  320. * ``EmailField`` and ``URLField`` no longer accept the ``strip`` keyword
  321. argument. Remove it because it doesn't have an effect in older versions of
  322. Django as these fields alway strip whitespace.
  323. * The ``checked`` attribute rendered by form widgets now uses HTML5 boolean
  324. syntax rather than XHTML's ``checked='checked'``.
  325. * :meth:`RelatedManager.add()
  326. <django.db.models.fields.related.RelatedManager.add>`,
  327. :meth:`~django.db.models.fields.related.RelatedManager.remove`,
  328. :meth:`~django.db.models.fields.related.RelatedManager.clear`, and
  329. :meth:`~django.db.models.fields.related.RelatedManager.set` now
  330. clear the ``prefetch_related()`` cache.
  331. * To prevent possible loss of saved settings,
  332. :func:`~django.test.utils.setup_test_environment` now raises an exception if
  333. called a second time before calling
  334. :func:`~django.test.utils.teardown_test_environment`.
  335. * The :djadmin:`makemessages` command now requires configured settings, like
  336. most other commands.
  337. * The undocumented ``DateTimeAwareJSONEncoder`` alias for
  338. :class:`~django.core.serializers.json.DjangoJSONEncoder` (renamed in Django
  339. 1.0) is removed.
  340. * The :class:`cached template loader <django.template.loaders.cached.Loader>`
  341. is now enabled if :setting:`DEBUG` is ``False`` and
  342. :setting:`OPTIONS['loaders'] <TEMPLATES-OPTIONS>` isn't specified. This could
  343. be backwards-incompatible if you have some :ref:`template tags that aren't
  344. thread safe <template_tag_thread_safety>`.
  345. * The prompt for stale content type deletion no longer occurs after running the
  346. ``migrate`` command. Use the new :djadmin:`remove_stale_contenttypes` command
  347. instead.
  348. * The admin's widget for ``IntegerField`` uses ``type="number"`` rather than
  349. ``type="text"``.
  350. * ETags are now parsed according to the :rfc:`7232` Conditional Requests
  351. specification rather than the syntax from :rfc:`2616`.
  352. .. _deprecated-features-1.11:
  353. Features deprecated in 1.11
  354. ===========================
  355. Miscellaneous
  356. -------------
  357. * ``contrib.auth``’s ``login()`` and ``logout()`` function-based views are
  358. deprecated in favor of new class-based views
  359. :class:`~django.contrib.auth.views.LoginView` and
  360. :class:`~django.contrib.auth.views.LogoutView`.
  361. * The unused ``extra_context`` parameter of
  362. ``contrib.auth.views.logout_then_login()`` is deprecated.
  363. * ``contrib.auth``’s ``password_change()``, ``password_change_done()``,
  364. ``password_reset()``, ``password_reset_done()``, ``password_reset_confirm()``,
  365. and ``password_reset_complete()`` function-based views are deprecated in favor
  366. of new class-based views
  367. :class:`~django.contrib.auth.views.PasswordChangeView`,
  368. :class:`~django.contrib.auth.views.PasswordChangeDoneView`,
  369. :class:`~django.contrib.auth.views.PasswordResetView`,
  370. :class:`~django.contrib.auth.views.PasswordResetDoneView`,
  371. :class:`~django.contrib.auth.views.PasswordResetConfirmView`, and
  372. :class:`~django.contrib.auth.views.PasswordResetCompleteView`.
  373. * ``django.test.runner.setup_databases()`` is moved to
  374. :func:`django.test.utils.setup_databases`. The old location is deprecated.
  375. * ``django.utils.translation.string_concat()`` is deprecated in
  376. favor of :func:`django.utils.text.format_lazy`. ``string_concat(*strings)``
  377. can be replaced by ``format_lazy('{}' * len(strings), *strings)``.
  378. * For the ``PyLibMCCache`` cache backend, passing ``pylibmc`` behavior settings
  379. as top-level attributes of ``OPTIONS`` is deprecated. Set them under a
  380. ``behaviors`` key within ``OPTIONS`` instead.
  381. * The ``host`` parameter of ``django.utils.http.is_safe_url()`` is deprecated
  382. in favor of the new ``allowed_hosts`` parameter.
  383. * Silencing exceptions raised while rendering the
  384. :ttag:`{% include %} <include>` template tag is deprecated as the behavior is
  385. often more confusing than helpful. In Django 2.1, the exception will be
  386. raised.