1.10.txt 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  1. =========================
  2. Django 1.10 release notes
  3. =========================
  4. *August 1, 2016*
  5. Welcome to Django 1.10!
  6. These release notes cover the :ref:`new features <whats-new-1.10>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-1.10>` you'll
  8. want to be aware of when upgrading from Django 1.9 or older versions. We've
  9. :ref:`dropped some features <removed-features-1.10>` that have reached the end
  10. of their deprecation cycle, and we've :ref:`begun the deprecation process for
  11. some features <deprecated-features-1.10>`.
  12. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  13. project.
  14. Python compatibility
  15. ====================
  16. Like Django 1.9, Django 1.10 requires Python 2.7, 3.4, or 3.5. We **highly
  17. recommend** and only officially support the latest release of each series.
  18. .. _whats-new-1.10:
  19. What's new in Django 1.10
  20. =========================
  21. Full text search for PostgreSQL
  22. -------------------------------
  23. ``django.contrib.postgres`` now includes a :doc:`collection of database
  24. functions </ref/contrib/postgres/search>` to allow the use of the full text
  25. search engine. You can search across multiple fields in your relational
  26. database, combine the searches with other lookups, use different language
  27. configurations and weightings, and rank the results by relevance.
  28. It also now includes trigram support, using the :lookup:`trigram_similar`
  29. lookup, and the :class:`~django.contrib.postgres.search.TrigramSimilarity` and
  30. :class:`~django.contrib.postgres.search.TrigramDistance` expressions.
  31. New-style middleware
  32. --------------------
  33. :doc:`A new style of middleware is introduced </topics/http/middleware>` to
  34. solve the lack of strict request/response layering of the old-style of
  35. middleware described in `DEP 0005
  36. <https://github.com/django/deps/blob/main/final/0005-improved-middleware.rst>`_.
  37. You'll need to :ref:`adapt old, custom middleware <upgrading-middleware>` and
  38. switch from the ``MIDDLEWARE_CLASSES`` setting to the new :setting:`MIDDLEWARE`
  39. setting to take advantage of the improvements.
  40. Official support for Unicode usernames
  41. --------------------------------------
  42. The :class:`~django.contrib.auth.models.User` model in ``django.contrib.auth``
  43. originally only accepted ASCII letters and numbers in usernames. Although it
  44. wasn't a deliberate choice, Unicode characters have always been accepted when
  45. using Python 3.
  46. The username validator now explicitly accepts Unicode characters by
  47. default on Python 3 only.
  48. Custom user models may use the new
  49. :class:`~django.contrib.auth.validators.ASCIIUsernameValidator` or
  50. :class:`~django.contrib.auth.validators.UnicodeUsernameValidator`.
  51. Minor features
  52. --------------
  53. :mod:`django.contrib.admin`
  54. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. * For sites running on a subpath, the default :attr:`URL for the "View site"
  56. link <django.contrib.admin.AdminSite.site_url>` at the top of each admin page
  57. will now point to ``request.META['SCRIPT_NAME']`` if set, instead of ``/``.
  58. * The success message that appears after adding or editing an object now
  59. contains a link to the object's change form.
  60. * All inline JavaScript is removed so you can enable the
  61. ``Content-Security-Policy`` HTTP header if you wish.
  62. * The new :attr:`InlineModelAdmin.classes
  63. <django.contrib.admin.InlineModelAdmin.classes>` attribute allows specifying
  64. classes on inline fieldsets. Inlines with a ``collapse`` class will be
  65. initially collapsed and their header will have a small "show" link.
  66. * If a user doesn't have the add permission, the ``object-tools`` block on a
  67. model's changelist will now be rendered (without the add button). This makes
  68. it easier to add custom tools in this case.
  69. * The :class:`~django.contrib.admin.models.LogEntry` model now stores change
  70. messages in a JSON structure so that the message can be dynamically translated
  71. using the current active language. A new ``LogEntry.get_change_message()``
  72. method is now the preferred way of retrieving the change message.
  73. * Selected objects for fields in ``ModelAdmin.raw_id_fields`` now have a link
  74. to object's change form.
  75. * Added "No date" and "Has date" choices for ``DateFieldListFilter`` if the
  76. field is nullable.
  77. * The jQuery library embedded in the admin is upgraded from version 2.1.4 to
  78. 2.2.3.
  79. :mod:`django.contrib.auth`
  80. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. * Added support for the :ref:`Argon2 password hash <argon2_usage>`. It's
  82. recommended over PBKDF2, however, it's not the default as it requires a
  83. third-party library.
  84. * The default iteration count for the PBKDF2 password hasher has been increased
  85. by 25%. This backwards compatible change will not affect users who have
  86. subclassed ``django.contrib.auth.hashers.PBKDF2PasswordHasher`` to change the
  87. default value.
  88. * The ``django.contrib.auth.views.logout()`` view sends "no-cache" headers
  89. to prevent an issue where Safari caches redirects and prevents a user from
  90. being able to log out.
  91. * Added the optional ``backend`` argument to :func:`django.contrib.auth.login`
  92. to allow using it without credentials.
  93. * The new :setting:`LOGOUT_REDIRECT_URL` setting controls the redirect of the
  94. ``django.contrib.auth.views.logout()`` view, if the view doesn't get a
  95. ``next_page`` argument.
  96. * The new ``redirect_authenticated_user`` parameter for the
  97. ``django.contrib.auth.views.login()`` view allows redirecting
  98. authenticated users visiting the login page.
  99. * The new :class:`~django.contrib.auth.backends.AllowAllUsersModelBackend` and
  100. :class:`~django.contrib.auth.backends.AllowAllUsersRemoteUserBackend` ignore
  101. the value of ``User.is_active``, while
  102. :class:`~django.contrib.auth.backends.ModelBackend` and
  103. :class:`~django.contrib.auth.backends.RemoteUserBackend` now reject inactive
  104. users.
  105. :mod:`django.contrib.gis`
  106. ~~~~~~~~~~~~~~~~~~~~~~~~~
  107. * :ref:`Distance lookups <distance-lookups>` now accept expressions as the
  108. distance value parameter.
  109. * The new :attr:`GEOSGeometry.unary_union
  110. <django.contrib.gis.geos.GEOSGeometry.unary_union>` property computes the
  111. union of all the elements of this geometry.
  112. * Added the :meth:`GEOSGeometry.covers()
  113. <django.contrib.gis.geos.GEOSGeometry.covers>` binary predicate.
  114. * Added the :meth:`GDALBand.statistics()
  115. <django.contrib.gis.gdal.GDALBand.statistics>` method and
  116. :attr:`~django.contrib.gis.gdal.GDALBand.mean`
  117. and :attr:`~django.contrib.gis.gdal.GDALBand.std` attributes.
  118. * Added support for the :class:`~django.contrib.gis.db.models.MakeLine`
  119. aggregate and :class:`~django.contrib.gis.db.models.functions.GeoHash`
  120. function on SpatiaLite.
  121. * Added support for the
  122. :class:`~django.contrib.gis.db.models.functions.Difference`,
  123. :class:`~django.contrib.gis.db.models.functions.Intersection`, and
  124. :class:`~django.contrib.gis.db.models.functions.SymDifference`
  125. functions on MySQL.
  126. * Added support for instantiating empty GEOS geometries.
  127. * The new :attr:`~django.contrib.gis.geos.WKTWriter.trim` and
  128. :attr:`~django.contrib.gis.geos.WKTWriter.precision` properties
  129. of :class:`~django.contrib.gis.geos.WKTWriter` allow controlling
  130. output of the fractional part of the coordinates in WKT.
  131. * Added the :attr:`LineString.closed
  132. <django.contrib.gis.geos.LineString.closed>` and
  133. :attr:`MultiLineString.closed
  134. <django.contrib.gis.geos.MultiLineString.closed>` properties.
  135. * The :doc:`GeoJSON serializer </ref/contrib/gis/serializers>` now outputs the
  136. primary key of objects in the ``properties`` dictionary if specific fields
  137. aren't specified.
  138. * The ability to replicate input data on the :meth:`GDALBand.data()
  139. <django.contrib.gis.gdal.GDALBand.data>` method was added. Band data can
  140. now be updated with repeated values efficiently.
  141. * Added database functions
  142. :class:`~django.contrib.gis.db.models.functions.IsValid` and
  143. :class:`~django.contrib.gis.db.models.functions.MakeValid`, as well as the
  144. :lookup:`isvalid` lookup, all for PostGIS. This allows filtering and
  145. repairing invalid geometries on the database side.
  146. * Added raster support for all :doc:`spatial lookups
  147. </ref/contrib/gis/geoquerysets>`.
  148. :mod:`django.contrib.postgres`
  149. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  150. * For convenience, :class:`~django.contrib.postgres.fields.HStoreField` now
  151. casts its keys and values to strings.
  152. :mod:`django.contrib.sessions`
  153. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  154. * The :djadmin:`clearsessions` management command now removes file-based
  155. sessions.
  156. :mod:`django.contrib.sites`
  157. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  158. * The :class:`~django.contrib.sites.models.Site` model now supports
  159. :ref:`natural keys <topics-serialization-natural-keys>`.
  160. :mod:`django.contrib.staticfiles`
  161. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  162. * The :ttag:`static` template tag now uses ``django.contrib.staticfiles``
  163. if it's in ``INSTALLED_APPS``. This is especially useful for third-party apps
  164. which can now always use ``{% load static %}`` (instead of
  165. ``{% load staticfiles %}`` or ``{% load static from staticfiles %}``) and
  166. not worry about whether or not the ``staticfiles`` app is installed.
  167. * You can :ref:`more easily customize <customize-staticfiles-ignore-patterns>`
  168. the ``collectstatic --ignore`` option with a custom ``AppConfig``.
  169. Cache
  170. ~~~~~
  171. * The file-based cache backend now uses the highest pickling protocol.
  172. CSRF
  173. ~~~~
  174. * The default :setting:`CSRF_FAILURE_VIEW`, ``views.csrf.csrf_failure()`` now
  175. accepts an optional ``template_name`` parameter, defaulting to
  176. ``'403_csrf.html'``, to control the template used to render the page.
  177. * To protect against `BREACH`_ attacks, the CSRF protection mechanism now
  178. changes the form token value on every request (while keeping an invariant
  179. secret which can be used to validate the different tokens).
  180. .. _BREACH: http://breachattack.com/
  181. Database backends
  182. ~~~~~~~~~~~~~~~~~
  183. * Temporal data subtraction was unified on all backends.
  184. * If the database supports it, backends can set
  185. ``DatabaseFeatures.can_return_ids_from_bulk_insert=True`` and implement
  186. ``DatabaseOperations.fetch_returned_insert_ids()`` to set primary keys
  187. on objects created using ``QuerySet.bulk_create()``.
  188. * Added keyword arguments to the ``as_sql()`` methods of various expressions
  189. (``Func``, ``When``, ``Case``, and ``OrderBy``) to allow database backends to
  190. customize them without mutating ``self``, which isn't safe when using
  191. different database backends. See the ``arg_joiner`` and ``**extra_context``
  192. parameters of :meth:`Func.as_sql() <django.db.models.Func.as_sql>` for an
  193. example.
  194. File Storage
  195. ~~~~~~~~~~~~
  196. * Storage backends now present a timezone-aware API with new methods
  197. :meth:`~django.core.files.storage.Storage.get_accessed_time`,
  198. :meth:`~django.core.files.storage.Storage.get_created_time`, and
  199. :meth:`~django.core.files.storage.Storage.get_modified_time`. They return a
  200. timezone-aware ``datetime`` if :setting:`USE_TZ` is ``True`` and a naive
  201. ``datetime`` in the local timezone otherwise.
  202. * The new :meth:`Storage.generate_filename()
  203. <django.core.files.storage.Storage.generate_filename>` method makes it easier
  204. to implement custom storages that don't use the ``os.path`` calls previously
  205. in :class:`~django.db.models.FileField`.
  206. Forms
  207. ~~~~~
  208. * Form and widget ``Media`` is now served using
  209. :mod:`django.contrib.staticfiles` if installed.
  210. * The ``<input>`` tag rendered by :class:`~django.forms.CharField` now includes
  211. a ``minlength`` attribute if the field has a ``min_length``.
  212. * Required form fields now have the ``required`` HTML attribute. Set the new
  213. :attr:`Form.use_required_attribute <django.forms.Form.use_required_attribute>`
  214. attribute to ``False`` to disable it. The ``required`` attribute isn't
  215. included on forms of formsets because the browser validation may not be
  216. correct when adding and deleting formsets.
  217. Generic Views
  218. ~~~~~~~~~~~~~
  219. * The :class:`~django.views.generic.base.View` class can now be imported from
  220. ``django.views``.
  221. Internationalization
  222. ~~~~~~~~~~~~~~~~~~~~
  223. * The :func:`~django.conf.urls.i18n.i18n_patterns` helper function can now be
  224. used in a root URLConf specified using :attr:`request.urlconf
  225. <django.http.HttpRequest.urlconf>`.
  226. * By setting the new ``prefix_default_language`` parameter for
  227. :func:`~django.conf.urls.i18n.i18n_patterns` to ``False``, you can allow
  228. accessing the default language without a URL prefix.
  229. * :func:`~django.views.i18n.set_language` now returns a 204 status code (No
  230. Content) for AJAX requests when there is no ``next`` parameter in ``POST`` or
  231. ``GET``.
  232. * The :class:`~django.views.i18n.JavaScriptCatalog` and
  233. :class:`~django.views.i18n.JSONCatalog` class-based views supersede the
  234. deprecated ``javascript_catalog()`` and ``json_catalog()`` function-based
  235. views. The new views are almost equivalent to the old ones except that by
  236. default the new views collect all JavaScript strings in the ``djangojs``
  237. translation domain from all installed apps rather than only the JavaScript
  238. strings from :setting:`LOCALE_PATHS`.
  239. Management Commands
  240. ~~~~~~~~~~~~~~~~~~~
  241. * :func:`~django.core.management.call_command` now returns the value returned
  242. from the ``command.handle()`` method.
  243. * The new :option:`check --fail-level` option allows specifying the message
  244. level that will cause the command to exit with a non-zero status.
  245. * The new :option:`makemigrations --check` option makes the command exit
  246. with a non-zero status when model changes without migrations are detected.
  247. * :djadmin:`makemigrations` now displays the path to the migration files that
  248. it generates.
  249. * The :option:`shell --interface` option now accepts ``python`` to force use of
  250. the "plain" Python interpreter.
  251. * The new :option:`shell --command` option lets you run a command as Django and
  252. exit, instead of opening the interactive shell.
  253. * Added a warning to :djadmin:`dumpdata` if a proxy model is specified (which
  254. results in no output) without its concrete parent.
  255. * The new :attr:`BaseCommand.requires_migrations_checks
  256. <django.core.management.BaseCommand.requires_migrations_checks>` attribute
  257. may be set to ``True`` if you want your command to print a warning, like
  258. :djadmin:`runserver` does, if the set of migrations on disk don't match the
  259. migrations in the database.
  260. * To assist with testing, :func:`~django.core.management.call_command` now
  261. accepts a command object as the first argument.
  262. * The :djadmin:`shell` command supports tab completion on systems using
  263. ``libedit``, e.g. macOS.
  264. * The :djadmin:`inspectdb` command lets you choose what tables should be
  265. inspected by specifying their names as arguments.
  266. Migrations
  267. ~~~~~~~~~~
  268. * Added support for serialization of ``enum.Enum`` objects.
  269. * Added the ``elidable`` argument to the
  270. :class:`~django.db.migrations.operations.RunSQL` and
  271. :class:`~django.db.migrations.operations.RunPython` operations to allow them
  272. to be removed when squashing migrations.
  273. * Added support for :ref:`non-atomic migrations <non-atomic-migrations>` by
  274. setting the ``atomic`` attribute on a ``Migration``.
  275. * The ``migrate`` and ``makemigrations`` commands now :ref:`check for a
  276. consistent migration history <migration-history-consistency>`. If they find
  277. some unapplied dependencies of an applied migration,
  278. ``InconsistentMigrationHistory`` is raised.
  279. * The :func:`~django.db.models.signals.pre_migrate` and
  280. :func:`~django.db.models.signals.post_migrate` signals now dispatch their
  281. migration ``plan`` and ``apps``.
  282. Models
  283. ~~~~~~
  284. * Reverse foreign keys from proxy models are now propagated to their
  285. concrete class. The reverse relation attached by a
  286. :class:`~django.db.models.ForeignKey` pointing to a proxy model is now
  287. accessible as a descriptor on the proxied model class and may be referenced in
  288. queryset filtering.
  289. * The new :meth:`Field.rel_db_type() <django.db.models.Field.rel_db_type>`
  290. method returns the database column data type for fields such as ``ForeignKey``
  291. and ``OneToOneField`` that point to another field.
  292. * The :attr:`~django.db.models.Func.arity` class attribute is added to
  293. :class:`~django.db.models.Func`. This attribute can be used to set the number
  294. of arguments the function accepts.
  295. * Added :class:`~django.db.models.BigAutoField` which acts much like an
  296. :class:`~django.db.models.AutoField` except that it is guaranteed
  297. to fit numbers from ``1`` to ``9223372036854775807``.
  298. * :meth:`QuerySet.in_bulk() <django.db.models.query.QuerySet.in_bulk>`
  299. may be called without any arguments to return all objects in the queryset.
  300. * :attr:`~django.db.models.ForeignKey.related_query_name` now supports
  301. app label and class interpolation using the ``'%(app_label)s'`` and
  302. ``'%(class)s'`` strings.
  303. * Allowed overriding model fields inherited from abstract base classes.
  304. * The :func:`~django.db.models.prefetch_related_objects` function is now a
  305. public API.
  306. * :meth:`QuerySet.bulk_create() <django.db.models.query.QuerySet.bulk_create>`
  307. sets the primary key on objects when using PostgreSQL.
  308. * Added the :class:`~django.db.models.functions.Cast` database function.
  309. * A proxy model may now inherit multiple proxy models that share a common
  310. non-abstract parent class.
  311. * Added :class:`~django.db.models.functions.Extract` functions to extract
  312. datetime components as integers, such as year and hour.
  313. * Added :class:`~django.db.models.functions.Trunc` functions to truncate a date
  314. or datetime to a significant component. They enable queries like
  315. sales-per-day or sales-per-hour.
  316. * ``Model.__init__()`` now sets values of virtual fields from its keyword
  317. arguments.
  318. * The new :attr:`Meta.base_manager_name
  319. <django.db.models.Options.base_manager_name>` and
  320. :attr:`Meta.default_manager_name
  321. <django.db.models.Options.default_manager_name>` options allow controlling
  322. the :attr:`~django.db.models.Model._base_manager` and
  323. :attr:`~django.db.models.Model._default_manager`, respectively.
  324. Requests and Responses
  325. ~~~~~~~~~~~~~~~~~~~~~~
  326. * Added ``request.user`` to the debug view.
  327. * Added :class:`~django.http.HttpResponse` methods
  328. :meth:`~django.http.HttpResponse.readable()` and
  329. :meth:`~django.http.HttpResponse.seekable()` to make an instance a
  330. stream-like object and allow wrapping it with :py:class:`io.TextIOWrapper`.
  331. * Added the :attr:`HttpRequest.content_type
  332. <django.http.HttpRequest.content_type>` and
  333. :attr:`~django.http.HttpRequest.content_params` attributes which are
  334. parsed from the ``CONTENT_TYPE`` header.
  335. * The parser for ``request.COOKIES`` is simplified to better match the behavior
  336. of browsers. ``request.COOKIES`` may now contain cookies that are invalid
  337. according to :rfc:`6265` but are possible to set via ``document.cookie``.
  338. Serialization
  339. ~~~~~~~~~~~~~
  340. * The ``django.core.serializers.json.DjangoJSONEncoder`` now knows how to
  341. serialize lazy strings, typically used for translatable content.
  342. Templates
  343. ~~~~~~~~~
  344. * Added the ``autoescape`` option to the
  345. :class:`~django.template.backends.django.DjangoTemplates` backend and the
  346. :class:`~django.template.Engine` class.
  347. * Added the ``is`` and ``is not`` comparison operators to the :ttag:`if` tag.
  348. * Allowed :tfilter:`dictsort` to order a list of lists by an element at a
  349. specified index.
  350. * The :func:`~django.template.context_processors.debug` context processor
  351. contains queries for all database aliases instead of only the default alias.
  352. * Added relative path support for string arguments of the :ttag:`extends` and
  353. :ttag:`include` template tags.
  354. Tests
  355. ~~~~~
  356. * To better catch bugs, :class:`~django.test.TestCase` now checks deferrable
  357. database constraints at the end of each test.
  358. * Tests and test cases can be :ref:`marked with tags <topics-tagging-tests>`
  359. and run selectively with the new :option:`test --tag` and :option:`test
  360. --exclude-tag` options.
  361. * You can now login and use sessions with the test client even if
  362. :mod:`django.contrib.sessions` is not in :setting:`INSTALLED_APPS`.
  363. URLs
  364. ~~~~
  365. * An addition in :func:`django.setup()` allows URL resolving that happens
  366. outside of the request/response cycle (e.g. in management commands and
  367. standalone scripts) to take :setting:`FORCE_SCRIPT_NAME` into account when it
  368. is set.
  369. Validators
  370. ~~~~~~~~~~
  371. * :class:`~django.core.validators.URLValidator` now limits the length of
  372. domain name labels to 63 characters and the total length of domain
  373. names to 253 characters per :rfc:`1034`.
  374. * :func:`~django.core.validators.int_list_validator` now accepts an optional
  375. ``allow_negative`` boolean parameter, defaulting to ``False``, to allow
  376. negative integers.
  377. .. _backwards-incompatible-1.10:
  378. Backwards incompatible changes in 1.10
  379. ======================================
  380. .. warning::
  381. In addition to the changes outlined in this section, be sure to review the
  382. :ref:`removed-features-1.10` for the features that have reached the end of
  383. their deprecation cycle and therefore been removed. If you haven't updated
  384. your code within the deprecation timeline for a given feature, its removal
  385. may appear as a backwards incompatible change.
  386. Database backend API
  387. --------------------
  388. * GIS's ``AreaField`` uses an unspecified underlying numeric type that could in
  389. practice be any numeric Python type. ``decimal.Decimal`` values retrieved
  390. from the database are now converted to ``float`` to make it easier to combine
  391. them with values used by the GIS libraries.
  392. * In order to enable temporal subtraction you must set the
  393. ``supports_temporal_subtraction`` database feature flag to ``True`` and
  394. implement the ``DatabaseOperations.subtract_temporals()`` method. This
  395. method should return the SQL and parameters required to compute the
  396. difference in microseconds between the ``lhs`` and ``rhs`` arguments in the
  397. datatype used to store :class:`~django.db.models.DurationField`.
  398. ``select_related()`` prohibits non-relational fields for nested relations
  399. -------------------------------------------------------------------------
  400. Django 1.8 added validation for non-relational fields in ``select_related()``::
  401. >>> Book.objects.select_related('title')
  402. Traceback (most recent call last):
  403. ...
  404. FieldError: Non-relational field given in select_related: 'title'
  405. But it didn't prohibit nested non-relation fields as it does now::
  406. >>> Book.objects.select_related('author__name')
  407. Traceback (most recent call last):
  408. ...
  409. FieldError: Non-relational field given in select_related: 'name'
  410. ``_meta.get_fields()`` returns consistent reverse fields for proxy models
  411. -------------------------------------------------------------------------
  412. Before Django 1.10, the :meth:`~django.db.models.options.Options.get_fields`
  413. method returned different reverse fields when called on a proxy model compared
  414. to its proxied concrete class. This inconsistency was fixed by returning the
  415. full set of fields pointing to a concrete class or one of its proxies in both
  416. cases.
  417. :attr:`AbstractUser.username <django.contrib.auth.models.User.username>` ``max_length`` increased to 150
  418. --------------------------------------------------------------------------------------------------------
  419. A migration for :attr:`django.contrib.auth.models.User.username` is included.
  420. If you have a custom user model inheriting from ``AbstractUser``, you'll need
  421. to generate and apply a database migration for your user model.
  422. We considered an increase to 254 characters to more easily allow the use of
  423. email addresses (which are limited to 254 characters) as usernames but rejected
  424. it due to a MySQL limitation. When using the ``utf8mb4`` encoding (recommended
  425. for proper Unicode support), MySQL can only create unique indexes with 191
  426. characters by default. Therefore, if you need a longer length, please use a
  427. custom user model.
  428. If you want to preserve the 30 character limit for usernames, use a custom form
  429. when creating a user or changing usernames::
  430. from django.contrib.auth.forms import UserCreationForm
  431. class MyUserCreationForm(UserCreationForm):
  432. username = forms.CharField(
  433. max_length=30,
  434. help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.',
  435. )
  436. If you wish to keep this restriction in the admin, set ``UserAdmin.add_form``
  437. to use this form::
  438. from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
  439. from django.contrib.auth.models import User
  440. class UserAdmin(BaseUserAdmin):
  441. add_form = MyUserCreationForm
  442. admin.site.unregister(User)
  443. admin.site.register(User, UserAdmin)
  444. Dropped support for PostgreSQL 9.1
  445. ----------------------------------
  446. Upstream support for PostgreSQL 9.1 ends in September 2016. As a consequence,
  447. Django 1.10 sets PostgreSQL 9.2 as the minimum version it officially supports.
  448. ``runserver`` output goes through logging
  449. -----------------------------------------
  450. Request and response handling of the ``runserver`` command is sent to the
  451. :ref:`django-server-logger` logger instead of to ``sys.stderr``. If you
  452. disable Django's logging configuration or override it with your own, you'll
  453. need to add the appropriate logging configuration if you want to see that
  454. output::
  455. 'formatters': {
  456. 'django.server': {
  457. '()': 'django.utils.log.ServerFormatter',
  458. 'format': '[%(server_time)s] %(message)s',
  459. }
  460. },
  461. 'handlers': {
  462. 'django.server': {
  463. 'level': 'INFO',
  464. 'class': 'logging.StreamHandler',
  465. 'formatter': 'django.server',
  466. },
  467. },
  468. 'loggers': {
  469. 'django.server': {
  470. 'handlers': ['django.server'],
  471. 'level': 'INFO',
  472. 'propagate': False,
  473. }
  474. }
  475. ``auth.CustomUser`` and ``auth.ExtensionUser`` test models were removed
  476. -----------------------------------------------------------------------
  477. Since the introduction of migrations for the contrib apps in Django 1.8, the
  478. tables of these custom user test models were not created anymore making them
  479. unusable in a testing context.
  480. Apps registry is no longer auto-populated when unpickling models outside of Django
  481. ----------------------------------------------------------------------------------
  482. The apps registry is no longer auto-populated when unpickling models. This was
  483. added in Django 1.7.2 as an attempt to allow unpickling models outside of
  484. Django, such as in an RQ worker, without calling ``django.setup()``, but it
  485. creates the possibility of a deadlock. To adapt your code in the case of RQ,
  486. you can `provide your own worker script <https://python-rq.org/docs/workers/>`_
  487. that calls ``django.setup()``.
  488. Removed null assignment check for non-null foreign key fields
  489. -------------------------------------------------------------
  490. In older versions, assigning ``None`` to a non-nullable ``ForeignKey`` or
  491. ``OneToOneField`` raised ``ValueError('Cannot assign None: "model.field" does
  492. not allow null values.')``. For consistency with other model fields which don't
  493. have a similar check, this check is removed.
  494. Removed weak password hashers from the default ``PASSWORD_HASHERS`` setting
  495. ---------------------------------------------------------------------------
  496. Django 0.90 stored passwords as unsalted MD5. Django 0.91 added support for
  497. salted SHA1 with automatic upgrade of passwords when a user logs in. Django 1.4
  498. added PBKDF2 as the default password hasher.
  499. If you have an old Django project with MD5 or SHA1 (even salted) encoded
  500. passwords, be aware that these can be cracked fairly easily with today's
  501. hardware. To make Django users acknowledge continued use of weak hashers, the
  502. following hashers are removed from the default :setting:`PASSWORD_HASHERS`
  503. setting::
  504. 'django.contrib.auth.hashers.SHA1PasswordHasher'
  505. 'django.contrib.auth.hashers.MD5PasswordHasher'
  506. 'django.contrib.auth.hashers.UnsaltedSHA1PasswordHasher'
  507. 'django.contrib.auth.hashers.UnsaltedMD5PasswordHasher'
  508. 'django.contrib.auth.hashers.CryptPasswordHasher'
  509. Consider using a :ref:`wrapped password hasher <wrapping-password-hashers>` to
  510. strengthen the hashes in your database. If that's not feasible, add the
  511. :setting:`PASSWORD_HASHERS` setting to your project and add back any hashers
  512. that you need.
  513. You can check if your database has any of the removed hashers like this::
  514. from django.contrib.auth import get_user_model
  515. User = get_user_model()
  516. # Unsalted MD5/SHA1:
  517. User.objects.filter(password__startswith='md5$$')
  518. User.objects.filter(password__startswith='sha1$$')
  519. # Salted MD5/SHA1:
  520. User.objects.filter(password__startswith='md5$').exclude(password__startswith='md5$$')
  521. User.objects.filter(password__startswith='sha1$').exclude(password__startswith='sha1$$')
  522. # Crypt hasher:
  523. User.objects.filter(password__startswith='crypt$$')
  524. from django.db.models import CharField
  525. from django.db.models.functions import Length
  526. CharField.register_lookup(Length)
  527. # Unsalted MD5 passwords might not have an 'md5$$' prefix:
  528. User.objects.filter(password__length=32)
  529. ``Field.get_prep_lookup()`` and ``Field.get_db_prep_lookup()`` methods are removed
  530. ----------------------------------------------------------------------------------
  531. If you have a custom field that implements either of these methods, register a
  532. custom lookup for it. For example::
  533. from django.db.models import Field
  534. from django.db.models.lookups import Exact
  535. class MyField(Field):
  536. ...
  537. class MyFieldExact(Exact):
  538. def get_prep_lookup(self):
  539. # do_custom_stuff_for_myfield
  540. ....
  541. MyField.register_lookup(MyFieldExact)
  542. :mod:`django.contrib.gis`
  543. -------------------------
  544. * Support for SpatiaLite < 3.0 and GEOS < 3.3 is dropped.
  545. * The ``add_postgis_srs()`` backwards compatibility alias for
  546. ``django.contrib.gis.utils.add_srs_entry()`` is removed.
  547. * On Oracle/GIS, the :class:`~django.contrib.gis.db.models.functions.Area`
  548. aggregate function now returns a ``float`` instead of ``decimal.Decimal``.
  549. (It's still wrapped in a measure of square meters.)
  550. * The default :class:`~django.contrib.gis.geos.GEOSGeometry` representation (WKT
  551. output) is trimmed by default. That is, instead of
  552. ``POINT (23.0000000000000000 5.5000000000000000)``, you'll get
  553. ``POINT (23 5.5)``.
  554. Maximum size of a request body and the number of GET/POST parameters is limited
  555. -------------------------------------------------------------------------------
  556. Two new settings help mitigate denial-of-service attacks via large requests:
  557. * :setting:`DATA_UPLOAD_MAX_MEMORY_SIZE` limits the size that a request body
  558. may be. File uploads don't count towards this limit.
  559. * :setting:`DATA_UPLOAD_MAX_NUMBER_FIELDS` limits the number of GET/POST
  560. parameters that are parsed.
  561. Applications that receive unusually large form posts may need to tune these
  562. settings.
  563. Miscellaneous
  564. -------------
  565. * The ``repr()`` of a ``QuerySet`` is wrapped in ``<QuerySet >`` to
  566. disambiguate it from a plain list when debugging.
  567. * ``utils.version.get_version()`` returns :pep:`440` compliant release
  568. candidate versions (e.g. '1.10rc1' instead of '1.10c1').
  569. * CSRF token values are now required to be strings of 64 alphanumerics; values
  570. of 32 alphanumerics, as set by older versions of Django by default, are
  571. automatically replaced by strings of 64 characters. Other values are
  572. considered invalid. This should only affect developers or users who replace
  573. these tokens.
  574. * The ``LOGOUT_URL`` setting is removed as Django hasn't made use of it
  575. since pre-1.0. If you use it in your project, you can add it to your
  576. project's settings. The default value was ``'/accounts/logout/'``.
  577. * Objects with a ``close()`` method such as files and generators passed to
  578. :class:`~django.http.HttpResponse` are now closed immediately instead of when
  579. the WSGI server calls ``close()`` on the response.
  580. * A redundant ``transaction.atomic()`` call in ``QuerySet.update_or_create()``
  581. is removed. This may affect query counts tested by
  582. ``TransactionTestCase.assertNumQueries()``.
  583. * Support for ``skip_validation`` in ``BaseCommand.execute(**options)`` is
  584. removed. Use ``skip_checks`` (added in Django 1.7) instead.
  585. * :djadmin:`loaddata` now raises a ``CommandError`` instead of showing a
  586. warning when the specified fixture file is not found.
  587. * Instead of directly accessing the ``LogEntry.change_message`` attribute, it's
  588. now better to call the ``LogEntry.get_change_message()`` method which will
  589. provide the message in the current language.
  590. * The default error views now raise ``TemplateDoesNotExist`` if a nonexistent
  591. ``template_name`` is specified.
  592. * The unused ``choices`` keyword argument of the ``Select`` and
  593. ``SelectMultiple`` widgets' ``render()`` method is removed. The ``choices``
  594. argument of the ``render_options()`` method is also removed, making
  595. ``selected_choices`` the first argument.
  596. * Tests that violate deferrable database constraints will now error when run on
  597. a database that supports deferrable constraints.
  598. * Built-in management commands now use indexing of keys in ``options``, e.g.
  599. ``options['verbosity']``, instead of ``options.get()`` and no longer perform
  600. any type coercion. This could be a problem if you're calling commands using
  601. ``Command.execute()`` (which bypasses the argument parser that sets a default
  602. value) instead of :func:`~django.core.management.call_command`. Instead of
  603. calling ``Command.execute()``, pass the command object as the first argument
  604. to ``call_command()``.
  605. * :class:`~django.contrib.auth.backends.ModelBackend` and
  606. :class:`~django.contrib.auth.backends.RemoteUserBackend` now reject inactive
  607. users. This means that inactive users can't login and will be logged
  608. out if they are switched from ``is_active=True`` to ``False``. If you need
  609. the previous behavior, use the new
  610. :class:`~django.contrib.auth.backends.AllowAllUsersModelBackend` or
  611. :class:`~django.contrib.auth.backends.AllowAllUsersRemoteUserBackend`
  612. in :setting:`AUTHENTICATION_BACKENDS` instead.
  613. * In light of the previous change, the test client's
  614. :meth:`~django.test.Client.login()` method no longer always rejects inactive
  615. users but instead delegates this decision to the authentication backend.
  616. :meth:`~django.test.Client.force_login()` also delegates the decision to the
  617. authentication backend, so if you're using the default backends, you need to
  618. use an active user.
  619. * :func:`django.views.i18n.set_language` may now return a 204 status code for
  620. AJAX requests.
  621. * The ``base_field`` attribute of
  622. :class:`~django.contrib.postgres.fields.RangeField` is now a type of field,
  623. not an instance of a field. If you have created a custom subclass of
  624. :class:`~django.contrib.postgres.fields.RangeField`, you should change the
  625. ``base_field`` attribute.
  626. * Middleware classes are now initialized when the server starts rather than
  627. during the first request.
  628. * If you override ``is_authenticated()`` or ``is_anonymous()`` in a custom user
  629. model, you must convert them to attributes or properties as described in
  630. :ref:`the deprecation note <user-is-auth-anon-deprecation>`.
  631. * When using :attr:`ModelAdmin.save_as=True
  632. <django.contrib.admin.ModelAdmin.save_as>`, the "Save as new" button now
  633. redirects to the change view for the new object instead of to the model's
  634. changelist. If you need the previous behavior, set the new
  635. :attr:`ModelAdmin.save_as_continue
  636. <django.contrib.admin.ModelAdmin.save_as_continue>` attribute to ``False``.
  637. * Required form fields now have the ``required`` HTML attribute. Set the
  638. :attr:`Form.use_required_attribute <django.forms.Form.use_required_attribute>`
  639. attribute to ``False`` to disable it. You could also add the ``novalidate``
  640. attribute to ``<form>`` if you don't want browser validation. To disable
  641. the ``required`` attribute on custom widgets, override the
  642. :meth:`Widget.use_required_attribute() <django.forms.Widget.use_required_attribute>`
  643. method.
  644. * The WSGI handler no longer removes content of responses from ``HEAD``
  645. requests or responses with a ``status_code`` of 100-199, 204, or 304. Most
  646. Web servers already implement this behavior. Responses retrieved using the
  647. Django test client continue to have these "response fixes" applied.
  648. * ``Model.__init__()`` now receives ``django.db.models.DEFERRED`` as the value
  649. of deferred fields.
  650. * The ``Model._deferred`` attribute is removed as dynamic model classes when
  651. using ``QuerySet.defer()`` and ``only()`` is removed.
  652. * :meth:`Storage.save() <django.core.files.storage.Storage.save>` no longer
  653. replaces ``'\'`` with ``'/'``. This behavior is moved to
  654. :class:`~django.core.files.storage.FileSystemStorage` since this is a storage
  655. specific implementation detail. Any Windows user with a custom storage
  656. implementation that relies on this behavior will need to implement it in the
  657. custom storage's ``save()`` method.
  658. * Private :class:`~django.db.models.FileField` methods ``get_directory_name()``
  659. and ``get_filename()`` are no longer called (and are now deprecated) which is
  660. a backwards incompatible change for users overriding those methods on custom
  661. fields. To adapt such code, override ``FileField.generate_filename()`` or
  662. :meth:`Storage.generate_filename()
  663. <django.core.files.storage.Storage.generate_filename>` instead. It
  664. might be possible to use :attr:`~django.db.models.FileField.upload_to` also.
  665. * The subject of mail sent by ``AdminEmailHandler`` is no longer truncated at
  666. 989 characters. If you were counting on a limited length, truncate the subject
  667. yourself.
  668. * Private expressions ``django.db.models.expressions.Date`` and ``DateTime``
  669. are removed. The new :class:`~django.db.models.functions.Trunc` expressions
  670. provide the same functionality.
  671. * The ``_base_manager`` and ``_default_manager`` attributes are removed from
  672. model instances. They remain accessible on the model class.
  673. * Accessing a deleted field on a model instance, e.g. after ``del obj.field``,
  674. reloads the field's value instead of raising ``AttributeError``.
  675. * If you subclass ``AbstractBaseUser`` and override ``clean()``, be sure it
  676. calls ``super()``. :meth:`.AbstractBaseUser.normalize_username` is called in
  677. a new :meth:`.AbstractBaseUser.clean` method.
  678. * Private API ``django.forms.models.model_to_dict()`` returns a queryset rather
  679. than a list of primary keys for ``ManyToManyField``\s.
  680. * If ``django.contrib.staticfiles`` is
  681. installed, the :ttag:`static` template tag uses the ``staticfiles`` storage
  682. to construct the URL rather than simply joining the value with
  683. ``STATIC_ROOT``. The new approach encodes the URL, which could be
  684. backwards-incompatible in cases such as including a fragment in a path, e.g.
  685. ``{% static 'img.svg#fragment' %}``, since the ``#`` is encoded as ``%23``.
  686. To adapt, move the fragment outside the template tag:
  687. ``{% static 'img.svg' %}#fragment``.
  688. * When :setting:`USE_L10N` is ``True``, localization is now applied for the
  689. :tfilter:`date` and :tfilter:`time` filters when no format string is
  690. specified. The ``DATE_FORMAT`` and ``TIME_FORMAT`` specifiers from the active
  691. locale are used instead of the settings of the same name.
  692. .. _deprecated-features-1.10:
  693. Features deprecated in 1.10
  694. ===========================
  695. Direct assignment to a reverse foreign key or many-to-many relation
  696. -------------------------------------------------------------------
  697. Instead of assigning related objects using direct assignment::
  698. >>> new_list = [obj1, obj2, obj3]
  699. >>> e.related_set = new_list
  700. Use the :meth:`~django.db.models.fields.related.RelatedManager.set` method
  701. added in Django 1.9::
  702. >>> e.related_set.set([obj1, obj2, obj3])
  703. This prevents confusion about an assignment resulting in an implicit save.
  704. Non-timezone-aware :class:`~django.core.files.storage.Storage` API
  705. ------------------------------------------------------------------
  706. The old, non-timezone-aware methods ``accessed_time()``, ``created_time()``,
  707. and ``modified_time()`` are deprecated in favor of the new ``get_*_time()``
  708. methods.
  709. Third-party storage backends should implement the new methods and mark the old
  710. ones as deprecated. Until then, the new ``get_*_time()`` methods on the base
  711. :class:`~django.core.files.storage.Storage` class convert ``datetime``\s from
  712. the old methods as required and emit a deprecation warning as they do so.
  713. Third-party storage backends may retain the old methods as long as they
  714. wish to support earlier versions of Django.
  715. :mod:`django.contrib.gis`
  716. -------------------------
  717. * The ``get_srid()`` and ``set_srid()`` methods of
  718. :class:`~django.contrib.gis.geos.GEOSGeometry` are deprecated in favor
  719. of the :attr:`~django.contrib.gis.geos.GEOSGeometry.srid` property.
  720. * The ``get_x()``, ``set_x()``, ``get_y()``, ``set_y()``, ``get_z()``, and
  721. ``set_z()`` methods of :class:`~django.contrib.gis.geos.Point` are deprecated
  722. in favor of the ``x``, ``y``, and ``z`` properties.
  723. * The ``get_coords()`` and ``set_coords()`` methods of
  724. :class:`~django.contrib.gis.geos.Point` are deprecated in favor of the
  725. ``tuple`` property.
  726. * The ``cascaded_union`` property of
  727. :class:`~django.contrib.gis.geos.MultiPolygon` is deprecated in favor of the
  728. :attr:`~django.contrib.gis.geos.GEOSGeometry.unary_union` property.
  729. * The ``django.contrib.gis.utils.precision_wkt()`` function is deprecated in
  730. favor of :class:`~django.contrib.gis.geos.WKTWriter`.
  731. ``CommaSeparatedIntegerField`` model field
  732. ------------------------------------------
  733. ``CommaSeparatedIntegerField`` is deprecated in favor of
  734. :class:`~django.db.models.CharField` with the
  735. :func:`~django.core.validators.validate_comma_separated_integer_list`
  736. validator::
  737. from django.core.validators import validate_comma_separated_integer_list
  738. from django.db import models
  739. class MyModel(models.Model):
  740. numbers = models.CharField(..., validators=[validate_comma_separated_integer_list])
  741. If you're using Oracle, ``CharField`` uses a different database field type
  742. (``NVARCHAR2``) than ``CommaSeparatedIntegerField`` (``VARCHAR2``). Depending
  743. on your database settings, this might imply a different encoding, and thus a
  744. different length (in bytes) for the same contents. If your stored values are
  745. longer than the 4000 byte limit of ``NVARCHAR2``, you should use ``TextField``
  746. (``NCLOB``) instead. In this case, if you have any queries that group by the
  747. field (e.g. annotating the model with an aggregation or using ``distinct()``)
  748. you'll need to change them (to defer the field).
  749. Using a model name as a query lookup when ``default_related_name`` is set
  750. -------------------------------------------------------------------------
  751. Assume the following models::
  752. from django.db import models
  753. class Foo(models.Model):
  754. pass
  755. class Bar(models.Model):
  756. foo = models.ForeignKey(Foo)
  757. class Meta:
  758. default_related_name = 'bars'
  759. In older versions, :attr:`~django.db.models.Options.default_related_name`
  760. couldn't be used as a query lookup. This is fixed and support for the old
  761. lookup name is deprecated. For example, since ``default_related_name`` is set
  762. in model ``Bar``, instead of using the model name ``bar`` as the lookup::
  763. >>> bar = Bar.objects.get(pk=1)
  764. >>> Foo.objects.get(bar=bar)
  765. use the default_related_name ``bars``::
  766. >>> Foo.objects.get(bars=bar)
  767. .. _search-lookup-replacement:
  768. ``__search`` query lookup
  769. -------------------------
  770. The ``search`` lookup, which supports MySQL only and is extremely limited in
  771. features, is deprecated. Replace it with a custom lookup::
  772. from django.db import models
  773. class Search(models.Lookup):
  774. lookup_name = 'search'
  775. def as_mysql(self, compiler, connection):
  776. lhs, lhs_params = self.process_lhs(compiler, connection)
  777. rhs, rhs_params = self.process_rhs(compiler, connection)
  778. params = lhs_params + rhs_params
  779. return 'MATCH (%s) AGAINST (%s IN BOOLEAN MODE)' % (lhs, rhs), params
  780. models.CharField.register_lookup(Search)
  781. models.TextField.register_lookup(Search)
  782. .. _user-is-auth-anon-deprecation:
  783. Using ``User.is_authenticated()`` and ``User.is_anonymous()`` as methods
  784. ------------------------------------------------------------------------
  785. The ``is_authenticated()`` and ``is_anonymous()`` methods of
  786. :class:`~django.contrib.auth.models.AbstractBaseUser` and
  787. :class:`~django.contrib.auth.models.AnonymousUser` classes are now
  788. properties. They will still work as methods until Django 2.0, but all usage
  789. in Django now uses attribute access.
  790. For example, if you use
  791. :class:`~django.contrib.auth.middleware.AuthenticationMiddleware` and want
  792. to know whether the user is currently logged-in you would use::
  793. if request.user.is_authenticated:
  794. ... # Do something for logged-in users.
  795. else:
  796. ... # Do something for anonymous users.
  797. instead of ``request.user.is_authenticated()``.
  798. This change avoids accidental information leakage if you forget to call the
  799. method, e.g.::
  800. if request.user.is_authenticated:
  801. return sensitive_information
  802. If you override these methods in a custom user model, you must change them to
  803. properties or attributes.
  804. Django uses a ``CallableBool`` object to allow these attributes to work as both
  805. a property and a method. Thus, until the deprecation period ends, you cannot
  806. compare these properties using the ``is`` operator. That is, the following
  807. won't work::
  808. if request.user.is_authenticated is True:
  809. ...
  810. Custom manager classes available through ``prefetch_related`` must define a ``_apply_rel_filters()`` method
  811. -----------------------------------------------------------------------------------------------------------
  812. If you defined a custom manager class available through
  813. :meth:`~django.db.models.query.QuerySet.prefetch_related` you must make sure
  814. it defines a ``_apply_rel_filters()`` method.
  815. This method must accept a :class:`~django.db.models.query.QuerySet` instance
  816. as its single argument and return a filtered version of the queryset for the
  817. model instance the manager is bound to.
  818. The "escape" half of ``django.utils.safestring``
  819. ------------------------------------------------
  820. The ``mark_for_escaping()`` function and the classes it uses: ``EscapeData``,
  821. ``EscapeBytes``, ``EscapeText``, ``EscapeString``, and ``EscapeUnicode`` are
  822. deprecated.
  823. As a result, the "lazy" behavior of the ``escape`` filter (where it would
  824. always be applied as the last filter no matter where in the filter chain it
  825. appeared) is deprecated. The filter will change to immediately apply
  826. :func:`~django.utils.html.conditional_escape` in Django 2.0.
  827. ``Manager.use_for_related_fields`` and inheritance changes
  828. ----------------------------------------------------------
  829. ``Manager.use_for_related_fields`` is deprecated in favor of setting
  830. :attr:`Meta.base_manager_name <django.db.models.Options.base_manager_name>` on
  831. the model.
  832. Model ``Manager`` inheritance will follow MRO inheritance rules in Django 2.0,
  833. changing the current behavior where managers defined on non-abstract base
  834. classes aren't inherited by child classes. A deprecating warning with
  835. instructions on how to adapt your code is raised if you have any affected
  836. managers. You'll either redeclare a manager from an abstract model on the child
  837. class to override the manager from the concrete model, or you'll set the
  838. model's ``Meta.manager_inheritance_from_future=True`` option to opt-in to the
  839. new inheritance behavior.
  840. During the deprecation period, ``use_for_related_fields`` will be honored and
  841. raise a warning, even if a ``base_manager_name`` is set. This allows
  842. third-party code to preserve legacy behavior while transitioning to the new
  843. API. The warning can be silenced by setting
  844. ``silence_use_for_related_fields_deprecation=True`` on the manager.
  845. Miscellaneous
  846. -------------
  847. * The ``makemigrations --exit`` option is deprecated in favor of the
  848. :option:`makemigrations --check` option.
  849. * ``django.utils.functional.allow_lazy()`` is deprecated in favor of the new
  850. :func:`~django.utils.functional.keep_lazy` function which can be used with a
  851. more natural decorator syntax.
  852. * The ``shell --plain`` option is deprecated in favor of ``-i python`` or
  853. ``--interface python``.
  854. * Importing from the ``django.core.urlresolvers`` module is deprecated in
  855. favor of its new location, :mod:`django.urls`.
  856. * The template ``Context.has_key()`` method is deprecated in favor of ``in``.
  857. * The private attribute ``virtual_fields`` of ``Model._meta`` is
  858. deprecated in favor of ``private_fields``.
  859. * The private keyword arguments ``virtual_only`` in
  860. ``Field.contribute_to_class()`` and ``virtual`` in
  861. ``Model._meta.add_field()`` are deprecated in favor of ``private_only``
  862. and ``private``, respectively.
  863. * The ``javascript_catalog()`` and ``json_catalog()`` views are deprecated in
  864. favor of class-based views :class:`~django.views.i18n.JavaScriptCatalog`
  865. and :class:`~django.views.i18n.JSONCatalog`.
  866. * In multi-table inheritance, implicit promotion of a ``OneToOneField`` to a
  867. ``parent_link`` is deprecated. Add ``parent_link=True`` to such fields.
  868. * The private API ``Widget._format_value()`` is made public and renamed to
  869. :meth:`~django.forms.Widget.format_value`. The old name will work
  870. through a deprecation period.
  871. * Private ``FileField`` methods ``get_directory_name()`` and ``get_filename()``
  872. are deprecated in favor of performing this work in
  873. :meth:`Storage.generate_filename()
  874. <django.core.files.storage.Storage.generate_filename>`).
  875. * Old-style middleware that uses ``settings.MIDDLEWARE_CLASSES`` are
  876. deprecated. :ref:`Adapt old, custom middleware <upgrading-middleware>` and
  877. use the new :setting:`MIDDLEWARE` setting.
  878. .. _removed-features-1.10:
  879. Features removed in 1.10
  880. ========================
  881. These features have reached the end of their deprecation cycle and are removed
  882. in Django 1.10. See :ref:`deprecated-features-1.8` for details, including how
  883. to remove usage of these features.
  884. * Support for calling a ``SQLCompiler`` directly as an alias for calling its
  885. ``quote_name_unless_alias`` method is removed.
  886. * The ``cycle`` and ``firstof`` template tags are removed from the ``future``
  887. template tag library.
  888. * ``django.conf.urls.patterns()`` is removed.
  889. * Support for the ``prefix`` argument to
  890. ``django.conf.urls.i18n.i18n_patterns()`` is removed.
  891. * ``SimpleTestCase.urls`` is removed.
  892. * Using an incorrect count of unpacked values in the ``for`` template tag
  893. raises an exception rather than failing silently.
  894. * The ability to :func:`~django.urls.reverse` URLs using a dotted Python path
  895. is removed.
  896. * The ability to use a dotted Python path for the ``LOGIN_URL`` and
  897. ``LOGIN_REDIRECT_URL`` settings is removed.
  898. * Support for ``optparse`` is dropped for custom management commands.
  899. * The class ``django.core.management.NoArgsCommand`` is removed.
  900. * ``django.core.context_processors`` module is removed.
  901. * ``django.db.models.sql.aggregates`` module is removed.
  902. * ``django.contrib.gis.db.models.sql.aggregates`` module is removed.
  903. * The following methods and properties of ``django.db.sql.query.Query`` are
  904. removed:
  905. * Properties: ``aggregates`` and ``aggregate_select``
  906. * Methods: ``add_aggregate``, ``set_aggregate_mask``, and
  907. ``append_aggregate_mask``.
  908. * ``django.template.resolve_variable`` is removed.
  909. * The following private APIs are removed from
  910. :class:`django.db.models.options.Options` (``Model._meta``):
  911. * ``get_field_by_name()``
  912. * ``get_all_field_names()``
  913. * ``get_fields_with_model()``
  914. * ``get_concrete_fields_with_model()``
  915. * ``get_m2m_with_model()``
  916. * ``get_all_related_objects()``
  917. * ``get_all_related_objects_with_model()``
  918. * ``get_all_related_many_to_many_objects()``
  919. * ``get_all_related_m2m_objects_with_model()``
  920. * The ``error_message`` argument of ``django.forms.RegexField`` is removed.
  921. * The ``unordered_list`` filter no longer supports old style lists.
  922. * Support for string ``view`` arguments to ``url()`` is removed.
  923. * The backward compatible shim to rename ``django.forms.Form._has_changed()``
  924. to ``has_changed()`` is removed.
  925. * The ``removetags`` template filter is removed.
  926. * The ``remove_tags()`` and ``strip_entities()`` functions in
  927. ``django.utils.html`` is removed.
  928. * The ``is_admin_site`` argument to
  929. ``django.contrib.auth.views.password_reset()`` is removed.
  930. * ``django.db.models.field.subclassing.SubfieldBase`` is removed.
  931. * ``django.utils.checksums`` is removed.
  932. * The ``original_content_type_id`` attribute on
  933. ``django.contrib.admin.helpers.InlineAdminForm`` is removed.
  934. * The backwards compatibility shim to allow ``FormMixin.get_form()`` to be
  935. defined with no default value for its ``form_class`` argument is removed.
  936. * The following settings are removed, and you must upgrade to the
  937. :setting:`TEMPLATES` setting:
  938. * ``ALLOWED_INCLUDE_ROOTS``
  939. * ``TEMPLATE_CONTEXT_PROCESSORS``
  940. * ``TEMPLATE_DEBUG``
  941. * ``TEMPLATE_DIRS``
  942. * ``TEMPLATE_LOADERS``
  943. * ``TEMPLATE_STRING_IF_INVALID``
  944. * The backwards compatibility alias ``django.template.loader.BaseLoader`` is
  945. removed.
  946. * Django template objects returned by
  947. :func:`~django.template.loader.get_template` and
  948. :func:`~django.template.loader.select_template` no longer accept a
  949. :class:`~django.template.Context` in their
  950. :meth:`~django.template.backends.base.Template.render()` method.
  951. * :doc:`Template response APIs </ref/template-response>` enforce the use of
  952. :class:`dict` and backend-dependent template objects instead of
  953. :class:`~django.template.Context` and :class:`~django.template.Template`
  954. respectively.
  955. * The ``current_app`` parameter for the following function and classes is
  956. removed:
  957. * ``django.shortcuts.render()``
  958. * ``django.template.Context()``
  959. * ``django.template.RequestContext()``
  960. * ``django.template.response.TemplateResponse()``
  961. * The ``dictionary`` and ``context_instance`` parameters for the following
  962. functions are removed:
  963. * ``django.shortcuts.render()``
  964. * ``django.shortcuts.render_to_response()``
  965. * ``django.template.loader.render_to_string()``
  966. * The ``dirs`` parameter for the following functions is removed:
  967. * ``django.template.loader.get_template()``
  968. * ``django.template.loader.select_template()``
  969. * ``django.shortcuts.render()``
  970. * ``django.shortcuts.render_to_response()``
  971. * Session verification is enabled regardless of whether or not
  972. ``'django.contrib.auth.middleware.SessionAuthenticationMiddleware'`` is in
  973. ``MIDDLEWARE_CLASSES``. ``SessionAuthenticationMiddleware`` no longer has
  974. any purpose and can be removed from ``MIDDLEWARE_CLASSES``. It's kept as
  975. a stub until Django 2.0 as a courtesy for users who don't read this note.
  976. * Private attribute ``django.db.models.Field.related`` is removed.
  977. * The ``--list`` option of the ``migrate`` management command is removed.
  978. * The ``ssi`` template tag is removed.
  979. * Support for the ``=`` comparison operator in the ``if`` template tag is
  980. removed.
  981. * The backwards compatibility shims to allow ``Storage.get_available_name()``
  982. and ``Storage.save()`` to be defined without a ``max_length`` argument are
  983. removed.
  984. * Support for the legacy ``%(<foo>)s`` syntax in ``ModelFormMixin.success_url``
  985. is removed.
  986. * ``GeoQuerySet`` aggregate methods ``collect()``, ``extent()``, ``extent3d()``,
  987. ``make_line()``, and ``unionagg()`` are removed.
  988. * The ability to specify ``ContentType.name`` when creating a content type
  989. instance is removed.
  990. * Support for the old signature of ``allow_migrate`` is removed.
  991. * Support for the syntax of ``{% cycle %}`` that uses comma-separated arguments
  992. is removed.
  993. * The warning that :class:`~django.core.signing.Signer` issued when given an
  994. invalid separator is now a ``ValueError``.