1.8.txt 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300
  1. ============================================
  2. Django 1.8 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. Welcome to Django 1.8!
  5. These release notes cover the `new features`_, as well as some `backwards
  6. incompatible changes`_ you'll want to be aware of when upgrading from Django
  7. 1.6 or older versions. We've also `begun the deprecation process for some
  8. features`_, and some features have reached the end of their deprecation process
  9. and `have been removed`_.
  10. Django 1.8 has been designated as Django's second :ref:`"Long-Term Support"
  11. (LTS) <lts-releases>` release. It will receive security updates for at least
  12. three years after its release. Support for the previous LTS, Django 1.4, will
  13. end 6 months from the release date of Django 1.8.
  14. .. _`new features`: `What's new in Django 1.8`_
  15. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.8`_
  16. .. _`begun the deprecation process for some features`: `Features deprecated in 1.8`_
  17. .. _`have been removed`: `Features removed in 1.8`_
  18. Python compatibility
  19. ====================
  20. Like Django 1.7, Django 1.8 requires Python 2.7 or above, though we
  21. **highly recommend** the latest minor release.
  22. What's new in Django 1.8
  23. ========================
  24. Security enhancements
  25. ~~~~~~~~~~~~~~~~~~~~~
  26. Several features of the django-secure_ third-party library have been
  27. integrated into Django. :class:`django.middleware.security.SecurityMiddleware`
  28. provides several security enhancements to the request/response cycle. The new
  29. :djadminopt:`--deploy` option of the :djadmin:`check` command allows you to
  30. check your production settings file for ways to increase the security of your
  31. site.
  32. .. _django-secure: https://pypi.python.org/pypi/django-secure
  33. New PostgreSQL specific functionality
  34. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. Django now has a module with extensions for PostgreSQL specific features, such
  36. as :class:`~django.contrib.postgres.fields.ArrayField`,
  37. :class:`~django.contrib.postgres.fields.HStoreField`, and :lookup:`unaccent`
  38. lookup. A full breakdown of the features is available :doc:`in the
  39. documentation </ref/contrib/postgres/index>`.
  40. New data types
  41. ~~~~~~~~~~~~~~
  42. * Django now has a :class:`~django.db.models.UUIDField` for storing
  43. universally unique identifiers. It is stored as the native ``uuid`` data type
  44. on PostgreSQL and as a fixed length character field on other backends. There
  45. is a corresponding :class:`form field <django.forms.UUIDField>`.
  46. * Django now has a :class:`~django.db.models.DurationField` for storing periods
  47. of time - modeled in Python by :class:`~python:datetime.timedelta`. It is
  48. stored in the native ``interval`` data type on PostgreSQL and as a ``bigint``
  49. of microseconds on other backends. Date and time related arithmetic has also
  50. been improved on all backends. There is a corresponding :class:`form field
  51. <django.forms.DurationField>`.
  52. Query Expressions
  53. ~~~~~~~~~~~~~~~~~
  54. :doc:`Query Expressions </ref/models/expressions>` allow users to create,
  55. customize, and compose complex SQL expressions. This has enabled annotate
  56. to accept expressions other than aggregates. Aggregates are now able to
  57. reference multiple fields, as well as perform arithmetic, similar to ``F()``
  58. objects.
  59. ``TestCase`` data setup
  60. ~~~~~~~~~~~~~~~~~~~~~~~
  61. :class:`~django.test.TestCase` has been refactored to allow for data
  62. initialization at the class level using transactions and savepoints. Database
  63. backends which do not support transactions, like MySQL with the MyISAM storage
  64. engine, will still be able to run these tests but won't benefit from the
  65. improvements. Tests are now run within two nested
  66. :func:`~django.db.transaction.atomic()` blocks: one for the whole class and one
  67. for each test.
  68. * The class method
  69. :meth:`TestCase.setUpTestData() <django.test.TestCase.setUpTestData>` adds
  70. the ability to setup test data at the class level. Using this technique can
  71. speed up the tests as compared to using ``setUp()``.
  72. * Fixture loading within ``TestCase`` is now performed once for the whole
  73. ``TestCase``.
  74. Minor features
  75. ~~~~~~~~~~~~~~
  76. :mod:`django.contrib.admin`
  77. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  78. * :class:`~django.contrib.admin.ModelAdmin` now has a
  79. :meth:`~django.contrib.admin.ModelAdmin.has_module_permission`
  80. method to allow limiting access to the module on the admin index page.
  81. * :class:`~django.contrib.admin.InlineModelAdmin` now has an attribute
  82. :attr:`~django.contrib.admin.InlineModelAdmin.show_change_link` that
  83. supports showing a link to an inline object's change form.
  84. * Use the new ``django.contrib.admin.RelatedOnlyFieldListFilter`` in
  85. :attr:`ModelAdmin.list_filter <django.contrib.admin.ModelAdmin.list_filter>`
  86. to limit the ``list_filter`` choices to foreign objects which are attached to
  87. those from the ``ModelAdmin``.
  88. * The :meth:`ModelAdmin.delete_view()
  89. <django.contrib.admin.ModelAdmin.delete_view>` displays a summary of objects
  90. to be deleted on the deletion confirmation page.
  91. * The jQuery library embedded in the admin has been upgraded to version 1.11.1.
  92. * You can now specify :attr:`AdminSite.site_url
  93. <django.contrib.admin.AdminSite.site_url>` in order to display a link to the
  94. front-end site.
  95. * You can now specify :attr:`ModelAdmin.show_full_result_count
  96. <django.contrib.admin.ModelAdmin.show_full_result_count>` to control whether
  97. or not the full count of objects should be displayed on a filtered admin page.
  98. * The ``AdminSite.password_change()`` method now has an ``extra_context``
  99. parameter.
  100. :mod:`django.contrib.admindocs`
  101. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  102. * reStructuredText is now parsed in model docstrings.
  103. :mod:`django.contrib.auth`
  104. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  105. * Authorization backends can now raise
  106. :class:`~django.core.exceptions.PermissionDenied` in
  107. :meth:`~django.contrib.auth.models.User.has_perm`
  108. and :meth:`~django.contrib.auth.models.User.has_module_perms`
  109. to short-circuit permission checking.
  110. * :class:`~django.contrib.auth.forms.PasswordResetForm` now
  111. has a method :meth:`~django.contrib.auth.forms.PasswordResetForm.send_email`
  112. that can be overridden to customize the mail to be sent.
  113. * The ``max_length`` of :attr:`Permission.name
  114. <django.contrib.auth.models.Permission.name>` has been increased from 50 to
  115. 255 characters. Please run the database migration.
  116. * :attr:`~django.contrib.auth.models.CustomUser.USERNAME_FIELD` and
  117. :attr:`~django.contrib.auth.models.CustomUser.REQUIRED_FIELDS` now supports
  118. :class:`~django.db.models.ForeignKey`\s.
  119. :mod:`django.contrib.gis`
  120. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  121. * A new :doc:`GeoJSON serializer </ref/contrib/gis/serializers>` is now
  122. available.
  123. * The Spatialite backend now supports ``Collect`` and ``Extent`` aggregates
  124. when the database version is 3.0 or later.
  125. * The PostGIS 2 ``CREATE EXTENSION postgis`` and the Spatialite
  126. ``SELECT InitSpatialMetaData`` initialization commands are now automatically
  127. run by :djadmin:`migrate`.
  128. * Compatibility shims for ``SpatialRefSys`` and ``GeometryColumns`` changed in
  129. Django 1.2 have been removed.
  130. * All GDAL-related exceptions are now raised with ``GDALException``. The former
  131. ``OGRException`` has been kept for backwards compatibility but should not be
  132. used any longer.
  133. :mod:`django.contrib.messages`
  134. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  135. * ...
  136. :mod:`django.contrib.redirects`
  137. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  138. * ...
  139. :mod:`django.contrib.sessions`
  140. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  141. * Session cookie is now deleted after
  142. :meth:`~django.contrib.sessions.backends.base.SessionBase.flush()` is called.
  143. :mod:`django.contrib.sitemaps`
  144. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  145. * The new :attr:`Sitemap.i18n <django.contrib.sitemaps.Sitemap.i18n>` attribute
  146. allows you to generate a sitemap based on the :setting:`LANGUAGES` setting.
  147. :mod:`django.contrib.sites`
  148. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  149. * :func:`~django.contrib.sites.shortcuts.get_current_site` will now lookup
  150. the current site based on :meth:`request.get_host()
  151. <django.http.HttpRequest.get_host>` if the :setting:`SITE_ID` setting is not
  152. defined.
  153. * The default :class:`~django.contrib.sites.models.Site` created when running
  154. ``migrate`` now respects the :setting:`SITE_ID` setting (instead of always
  155. using ``pk=1``).
  156. :mod:`django.contrib.staticfiles`
  157. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  158. * ...
  159. :mod:`django.contrib.syndication`
  160. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  161. * ...
  162. Cache
  163. ^^^^^
  164. * The ``incr()`` method of the
  165. ``django.core.cache.backends.locmem.LocMemCache`` backend is now thread-safe.
  166. Cryptography
  167. ^^^^^^^^^^^^
  168. * The ``max_age`` parameter of the
  169. :meth:`django.core.signing.TimestampSigner.unsign` method now also accept a
  170. :py:class:`datetime.timedelta` object.
  171. Database backends
  172. ^^^^^^^^^^^^^^^^^
  173. * The MySQL backend no longer strips microseconds from ``datetime`` values as
  174. MySQL 5.6.4 and up supports fractional seconds depending on the declaration
  175. of the datetime field (when ``DATETIME`` includes fractional precision greater
  176. than 0). New datetime database columns created with Django 1.8 and MySQL 5.6.4
  177. and up will support microseconds. See the :ref:`MySQL database notes
  178. <mysql-fractional-seconds>` for more details.
  179. Email
  180. ^^^^^
  181. * :ref:`Email backends <topic-email-backends>` now support the context manager
  182. protocol for opening and closing connections.
  183. * The SMTP email backend now supports ``keyfile`` and ``certfile``
  184. authentication with the :setting:`EMAIL_SSL_CERTFILE` and
  185. :setting:`EMAIL_SSL_KEYFILE` settings.
  186. * The SMTP :class:`~django.core.mail.backends.smtp.EmailBackend` now supports
  187. setting the ``timeout`` parameter with the :setting:`EMAIL_TIMEOUT` setting.
  188. * :class:`~django.core.mail.EmailMessage` and ``EmailMultiAlternatives`` now
  189. support the ``reply_to`` parameter.
  190. File Storage
  191. ^^^^^^^^^^^^
  192. * ...
  193. File Uploads
  194. ^^^^^^^^^^^^
  195. * ...
  196. Forms
  197. ^^^^^
  198. * Form widgets now render attributes with a value of ``True`` or ``False``
  199. as HTML5 boolean attributes.
  200. * The new :meth:`~django.forms.Form.has_error()` method allows checking
  201. if a specific error has happened.
  202. * If :attr:`~django.forms.Form.required_css_class` is defined on a form, then
  203. the ``<label>`` tags for required fields will have this class present in its
  204. attributes.
  205. * The rendering of non-field errors in unordered lists (``<ul>``) now includes
  206. ``nonfield`` in its list of classes to distinguish them from field-specific
  207. errors.
  208. * :class:`~django.forms.Field` now accepts a
  209. :attr:`~django.forms.Field.label_suffix` argument, which will override the
  210. form's :attr:`~django.forms.Form.label_suffix`. This enables customizing the
  211. suffix on a per-field basis — previously it wasn't possible to override
  212. a form's :attr:`~django.forms.Form.label_suffix` while using shortcuts such
  213. as ``{{ form.as_p }}`` in templates.
  214. * :class:`~django.forms.extras.widgets.SelectDateWidget` now accepts an
  215. :attr:`~django.forms.extras.widgets.SelectDateWidget.empty_label` argument, which will
  216. override the top list choice label when :class:`~django.forms.DateField` is not required.
  217. * After an :class:`~django.forms.ImageField` has been cleaned and validated, the
  218. ``UploadedFile`` object will have an additional ``image`` attribute containing
  219. the Pillow ``Image`` instance used to check if the file was a valid image. It
  220. will also update ``UploadedFile.content_type`` with the image's content type
  221. as determined by Pillow.
  222. * You can now pass a callable that returns an iterable of choices when
  223. instantiating a :class:`~django.forms.ChoiceField`.
  224. Generic Views
  225. ^^^^^^^^^^^^^
  226. * Generic views that use :class:`~django.views.generic.list.MultipleObjectMixin`
  227. may now specify the ordering applied to the
  228. :attr:`~django.views.generic.list.MultipleObjectMixin.queryset` by setting
  229. :attr:`~django.views.generic.list.MultipleObjectMixin.ordering` or overriding
  230. :meth:`~django.views.generic.list.MultipleObjectMixin.get_ordering()`.
  231. * The new :attr:`SingleObjectMixin.query_pk_and_slug
  232. <django.views.generic.detail.SingleObjectMixin.query_pk_and_slug>`
  233. attribute allows changing the behavior of
  234. :meth:`~django.views.generic.detail.SingleObjectMixin.get_object()`
  235. so that it'll perform its lookup using both the primary key and the slug.
  236. * The :meth:`~django.views.generic.edit.FormMixin.get_form()` method doesn't
  237. require a ``form_class`` to be provided anymore. If not provided ``form_class``
  238. defaults to :meth:`~django.views.generic.edit.FormMixin.get_form_class()`.
  239. Internationalization
  240. ^^^^^^^^^^^^^^^^^^^^
  241. * :setting:`FORMAT_MODULE_PATH` can now be a list of strings representing
  242. module paths. This allows importing several format modules from different
  243. reusable apps. It also allows overriding those custom formats in your main
  244. Django project.
  245. Logging
  246. ^^^^^^^
  247. * The :class:`django.utils.log.AdminEmailHandler` class now has a
  248. :meth:`~django.utils.log.AdminEmailHandler.send_mail` method to make it more
  249. subclass friendly.
  250. Management Commands
  251. ^^^^^^^^^^^^^^^^^^^
  252. * :djadmin:`dumpdata` now has the option :djadminopt:`--output` which allows
  253. specifying the file to which the serialized data is written.
  254. * :djadmin:`makemessages` and :djadmin:`compilemessages` now have the option
  255. :djadminopt:`--exclude` which allows exclusion of specific locales from
  256. processing.
  257. * :djadmin:`compilemessages` now has a ``--use-fuzzy`` or ``-f`` option which
  258. includes fuzzy translations into compiled files.
  259. * The :djadminopt:`--ignorenonexistent` option of the :djadmin:`loaddata`
  260. management command now ignores data for models that no longer exist.
  261. * :djadmin:`runserver` now uses daemon threads for faster reloading.
  262. * :djadmin:`inspectdb` now outputs ``Meta.unique_together``. It is also able to
  263. introspect :class:`~django.db.models.AutoField` for MySQL and PostgreSQL
  264. databases.
  265. * When calling management commands from code through :ref:`call_command
  266. <call-command>` and passing options, the option name can match the command
  267. line option name (without the initial dashes) or the final option destination
  268. variable name, but in either case, the resulting option received by the
  269. command is now always the ``dest`` name specified in the command option
  270. definition (as long as the command uses the new :py:mod:`argparse` module).
  271. * The :djadmin:`dbshell` command now supports MySQL's optional SSL certificate
  272. authority setting (``--ssl-ca``).
  273. * The :djadminopt:`--name` option for :djadmin:`makemigrations` allows you to
  274. to give the migration(s) a custom name instead of a generated one.
  275. * The :djadmin:`loaddata` command now prevents repeated fixture loading. If
  276. :setting:`FIXTURE_DIRS` contains duplicates or a default fixture directory
  277. path (``app_name/fixtures``), an exception is raised.
  278. * :djadmin:`makemigrations` now supports an :djadminopt:`--exit` option to
  279. exit with an error code if no migrations are created.
  280. Middleware
  281. ^^^^^^^^^^
  282. * The :attr:`CommonMiddleware.response_redirect_class
  283. <django.middleware.common.CommonMiddleware.response_redirect_class>`
  284. attribute allows you to customize the redirects issued by the middleware.
  285. * A debug message will be logged to the ``django.request`` logger when a
  286. middleware raises a :exc:`~django.core.exceptions.MiddlewareNotUsed` exception
  287. in :setting:`DEBUG` mode.
  288. Migrations
  289. ^^^^^^^^^^
  290. * The :class:`~django.db.migrations.operations.RunSQL` operation can now handle
  291. parameters passed to the SQL statements.
  292. * It is now possible to have migrations (most probably :ref:`data migrations
  293. <data-migrations>`) for applications without models.
  294. * Migrations can now :ref:`serialize model managers
  295. <using-managers-in-migrations>` as part of the model state.
  296. Models
  297. ^^^^^^
  298. * Django now logs at most 9000 queries in ``connections.queries``, in order
  299. to prevent excessive memory usage in long-running processes in debug mode.
  300. * There is now a model ``Meta`` option to define a
  301. :attr:`default related name <django.db.models.Options.default_related_name>`
  302. for all relational fields of a model.
  303. * Pickling models and querysets across different versions of Django isn't
  304. officially supported (it may work, but there's no guarantee). An extra
  305. variable that specifies the current Django version is now added to the
  306. pickled state of models and querysets, and Django raises a ``RuntimeWarning``
  307. when these objects are unpickled in a different version than the one in
  308. which they were pickled.
  309. * Added :meth:`Model.from_db() <django.db.models.Model.from_db()>` which
  310. Django uses whenever objects are loaded using the ORM. The method allows
  311. customizing model loading behavior.
  312. * ``extra(select={...})`` now allows you to escape a literal ``%s`` sequence
  313. using ``%%s``.
  314. * :doc:`Custom Lookups</howto/custom-lookups>` can now be registered using
  315. a decorator pattern.
  316. * The new :attr:`Transform.bilateral <django.db.models.Transform.bilateral>`
  317. attribute allows creating bilateral transformations. These transformations
  318. are applied to both ``lhs`` and ``rhs`` when used in a lookup expression,
  319. providing opportunities for more sophisticated lookups.
  320. * SQL special characters (\, %, _) are now escaped properly when a pattern
  321. lookup (e.g. ``contains``, ``startswith``, etc.) is used with an ``F()``
  322. expression as the right-hand side. In those cases, the escaping is performed
  323. by the database, which can lead to somewhat complex queries involving nested
  324. ``REPLACE`` function calls.
  325. * You can now refresh model instances by using :meth:`Model.refresh_from_db()
  326. <django.db.models.Model.refresh_from_db>`.
  327. * You can now get the set of deferred fields for a model using
  328. :meth:`Model.get_deferred_fields() <django.db.models.Model.get_deferred_fields>`.
  329. Signals
  330. ^^^^^^^
  331. * Exceptions from the ``(receiver, exception)`` tuples returned by
  332. :meth:`Signal.send_robust() <django.dispatch.Signal.send_robust>` now have
  333. their traceback attached as a ``__traceback__`` attribute.
  334. * The ``environ`` argument, which contains the WSGI environment structure from
  335. the request, was added to the :data:`~django.core.signals.request_started`
  336. signal.
  337. System Check Framework
  338. ^^^^^^^^^^^^^^^^^^^^^^
  339. * :attr:`~django.core.checks.register` can now be used as a function.
  340. Templates
  341. ^^^^^^^^^
  342. * :tfilter:`urlize` now supports domain-only links that include characters after
  343. the top-level domain (e.g. ``djangoproject.com/`` and
  344. ``djangoproject.com/download/``).
  345. * :tfilter:`urlize` doesn't treat exclamation marks at the end of a domain or
  346. its query string as part of the URL (the URL in e.g. ``'djangoproject.com!``
  347. is ``djangoproject.com``)
  348. * Added a :class:`locmem.Loader <django.template.loaders.locmem.Loader>`
  349. class that loads Django templates from a Python dictionary.
  350. * The :ttag:`now` tag can now store its output in a context variable with the
  351. usual syntax: ``{% now 'j n Y' as varname %}``.
  352. Requests and Responses
  353. ^^^^^^^^^^^^^^^^^^^^^^
  354. * ``WSGIRequest`` now respects paths starting with ``//``.
  355. * The :meth:`HttpRequest.build_absolute_uri()
  356. <django.http.HttpRequest.build_absolute_uri>` method now handles paths
  357. starting with ``//`` correctly.
  358. * If :setting:`DEBUG` is ``True`` and a request raises a
  359. :exc:`~django.core.exceptions.SuspiciousOperation`, the response will be
  360. rendered with a detailed error page.
  361. * The ``query_string`` argument of :class:`~django.http.QueryDict` is now
  362. optional, defaulting to ``None``, so a blank ``QueryDict`` can now be
  363. instantiated with ``QueryDict()`` instead of ``QueryDict(None)`` or
  364. ``QueryDict('')``.
  365. * The ``GET`` and ``POST`` attributes of an :class:`~django.http.HttpRequest`
  366. object are now :class:`~django.http.QueryDict`\s rather than dictionaries,
  367. and the ``FILES`` attribute is now a ``MultiValueDict``.
  368. This brings this class into line with the documentation and with
  369. ``WSGIRequest``.
  370. * The :attr:`HttpResponse.charset <django.http.HttpResponse.charset>` attribute
  371. was added.
  372. * ``WSGIRequestHandler`` now follows RFC in converting URI to IRI, using
  373. ``uri_to_iri()``.
  374. * The :meth:`HttpRequest.get_full_path()
  375. <django.http.HttpRequest.get_full_path>` method now escapes unsafe characters
  376. from the path portion of a Uniform Resource Identifier (URI) properly.
  377. * :class:`~django.http.HttpResponse` now implements a few additional methods
  378. like :meth:`~django.http.HttpResponse.getvalue` so that instances can be used
  379. as stream objects.
  380. * The new :meth:`HttpResponse.setdefault()
  381. <django.http.HttpResponse.setdefault>` method allows setting a header unless
  382. it has already been set.
  383. Tests
  384. ^^^^^
  385. * The :class:`RequestFactory.trace() <django.test.RequestFactory>`
  386. and :class:`Client.trace() <django.test.Client.trace>` methods were
  387. implemented, allowing you to create ``TRACE`` requests in your tests.
  388. * The ``count`` argument was added to
  389. :meth:`~django.test.SimpleTestCase.assertTemplateUsed`. This allows you to
  390. assert that a template was rendered a specific number of times.
  391. * The new :meth:`~django.test.SimpleTestCase.assertJSONNotEqual` assertion
  392. allows you to test that two JSON fragments are not equal.
  393. * Added options to the :djadmin:`test` command to preserve the test database
  394. (:djadminopt:`--keepdb`) and to run the test cases in reverse order
  395. (:djadminopt:`--reverse`).
  396. * Added the :attr:`~django.test.Response.resolver_match` attribute to test
  397. client responses.
  398. * Added several settings that allow customization of test tablespace parameters
  399. for Oracle: :setting:`DATAFILE`, :setting:`DATAFILE_TMP`,
  400. :setting:`DATAFILE_MAXSIZE` and :setting:`DATAFILE_TMP_MAXSIZE`.
  401. * The :func:`~django.test.override_settings` decorator can now affect the
  402. master router in :setting:`DATABASE_ROUTERS`.
  403. * Added test client support for file uploads with file-like objects.
  404. Validators
  405. ^^^^^^^^^^
  406. * ...
  407. Backwards incompatible changes in 1.8
  408. =====================================
  409. .. warning::
  410. In addition to the changes outlined in this section, be sure to review the
  411. :ref:`deprecation plan <deprecation-removed-in-1.8>` for any features that
  412. have been removed. If you haven't updated your code within the
  413. deprecation timeline for a given feature, its removal may appear as a
  414. backwards incompatible change.
  415. Related object operations are run in a transaction
  416. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  417. Some operations on related objects such as
  418. :meth:`~django.db.models.fields.related.RelatedManager.add()` or
  419. :ref:`direct assignment<direct-assignment>` ran multiple data modifying
  420. queries without wrapping them in transactions. To reduce the risk of data
  421. corruption, all data modifying methods that affect multiple related objects
  422. (i.e. ``add()``, ``remove()``, ``clear()``, and :ref:`direct assignment
  423. <direct-assignment>`) now perform their data modifying queries from within a
  424. transaction, provided your database supports transactions.
  425. This has one backwards incompatible side effect, signal handlers triggered from
  426. these methods are now executed within the method's transaction and any
  427. exception in a signal handler will prevent the whole operation.
  428. Assigning unsaved objects to relations raises an error
  429. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  430. Assigning unsaved objects to a :class:`~django.db.models.ForeignKey`,
  431. :class:`~django.contrib.contenttypes.fields.GenericForeignKey`, and
  432. :class:`~django.db.models.OneToOneField` now raises a :exc:`ValueError`.
  433. Previously, the assignment of an unsaved object would be silently ignored.
  434. For example::
  435. >>> book = Book.objects.create(name="Django")
  436. >>> book.author = Author(name="John")
  437. >>> book.author.save()
  438. >>> book.save()
  439. >>> Book.objects.get(name="Django")
  440. >>> book.author
  441. >>>
  442. Now, an error will be raised to prevent data loss::
  443. >>> book.author = Author(name="john")
  444. Traceback (most recent call last):
  445. ...
  446. ValueError: Cannot assign "<Author: John>": "Author" instance isn't saved in the database.
  447. Management commands that only accept positional arguments
  448. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  449. If you have written a custom management command that only accepts positional
  450. arguments and you didn't specify the
  451. :attr:`~django.core.management.BaseCommand.args` command variable, you might
  452. get an error like ``Error: unrecognized arguments: ...``, as variable parsing
  453. is now based on :py:mod:`argparse` which doesn't implicitly accept positional
  454. arguments. You can make your command backwards compatible by simply setting the
  455. :attr:`~django.core.management.BaseCommand.args` class variable. However, if
  456. you don't have to keep compatibility with older Django versions, it's better to
  457. implement the new :meth:`~django.core.management.BaseCommand.add_arguments`
  458. method as described in :doc:`/howto/custom-management-commands`.
  459. Custom test management command arguments through test runner
  460. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  461. The method to add custom arguments to the `test` management command through the
  462. test runner has changed. Previously, you could provide an `option_list` class
  463. variable on the test runner to add more arguments (à la :py:mod:`optparse`).
  464. Now to implement the same behavior, you have to create an
  465. ``add_arguments(cls, parser)`` class method on the test runner and call
  466. ``parser.add_argument`` to add any custom arguments, as parser is now an
  467. :py:class:`argparse.ArgumentParser` instance.
  468. Model check ensures auto-generated column names are within limits specified by database
  469. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  470. A field name that's longer than the column name length supported by a database
  471. can create problems. For example, with MySQL you'll get an exception trying to
  472. create the column, and with PostgreSQL the column name is truncated by the
  473. database (you may see a warning in the PostgreSQL logs).
  474. A model check has been introduced to better alert users to this scenario before
  475. the actual creation of database tables.
  476. If you have an existing model where this check seems to be a false positive,
  477. for example on PostgreSQL where the name was already being truncated, simply
  478. use :attr:`~django.db.models.Field.db_column` to specify the name that's being
  479. used.
  480. The check also applies to the columns generated in an implicit
  481. ``ManyToManyField.through`` model. If you run into an issue there, use
  482. :attr:`~django.db.models.ManyToManyField.through` to create an explicit model
  483. and then specify :attr:`~django.db.models.Field.db_column` on its column(s)
  484. as needed.
  485. Query relation lookups now check object types
  486. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  487. Querying for model lookups now checks if the object passed is of correct type
  488. and raises a :exc:`ValueError` if not. Previously, Django didn't care if the
  489. object was of correct type; it just used the object's related field attribute
  490. (e.g. ``id``) for the lookup. Now, an error is raised to prevent incorrect
  491. lookups::
  492. >>> book = Book.objects.create(name="Django")
  493. >>> book = Book.objects.filter(author=book)
  494. Traceback (most recent call last):
  495. ...
  496. ValueError: Cannot query "<Book: Django>": Must be "Author" instance.
  497. Default ``EmailField.max_length`` increased to 254
  498. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  499. The old default 75 character ``max_length`` was not capable of storing all
  500. possible RFC3696/5321-compliant email addresses. In order to store all
  501. possible valid email addresses, the ``max_length`` has been increased to 254
  502. characters. You will need to generate and apply database migrations for your
  503. affected models (or add ``max_length=75`` if you wish to keep the length on
  504. your current fields). A migration for
  505. :attr:`django.contrib.auth.models.User.email` is included.
  506. Support for PostgreSQL versions older than 9.0
  507. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  508. The end of upstream support periods was reached in July 2014 for PostgreSQL 8.4.
  509. As a consequence, Django 1.8 sets 9.0 as the minimum PostgreSQL version it
  510. officially supports.
  511. This also includes dropping support for PostGIS 1.3 and 1.4 as these versions
  512. are not supported on versions of PostgreSQL later than 8.4.
  513. Django also now requires the use of Psycopg2 version 2.0.9 or higher.
  514. Support for MySQL versions older than 5.5
  515. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  516. The end of upstream support periods was reached in January 2012 for MySQL 5.0
  517. and December 2013 for MySQL 5.1. As a consequence, Django 1.8 sets 5.5 as the
  518. minimum MySQL version it officially supports.
  519. Support for Oracle versions older than 11.1
  520. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  521. The end of upstream support periods was reached in July 2010 for Oracle 9.2,
  522. January 2012 for Oracle 10.1, and July 2013 for Oracle 10.2. As a consequence,
  523. Django 1.8 sets 11.1 as the minimum Oracle version it officially supports.
  524. Specific privileges used instead of roles for tests on Oracle
  525. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  526. Earlier versions of Django granted the CONNECT and RESOURCE roles to the test
  527. user on Oracle. These roles have been deprecated, so Django 1.8 uses the
  528. specific underlying privileges instead. This changes the privileges required
  529. of the main user for running tests (unless the project is configured to avoid
  530. creating a test user). The exact privileges required now are detailed in
  531. :ref:`Oracle notes <oracle-notes>`.
  532. ``AbstractUser.last_login`` allows null values
  533. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  534. The :attr:`AbstractUser.last_login <django.contrib.auth.models.User.last_login>`
  535. field now allows null values. Previously, it defaulted to the time when the user
  536. was created which was misleading if the user never logged in. Please run the
  537. database migration. If your custom user inherits from ``AbstractUser`` and you
  538. wish to set ``last_login`` to ``NULL`` for users who haven't logged in, you can
  539. run this query::
  540. from django.db import models
  541. from django.contrib.auth import get_user_model
  542. from django.contrib.auth.models import AbstractBaseUser
  543. UserModel = get_user_model()
  544. if issubclass(UserModel, AbstractBaseUser):
  545. UserModel._default_manager.filter(
  546. last_login=models.F('date_joined')
  547. ).update(last_login=None)
  548. :mod:`django.contrib.gis`
  549. ~~~~~~~~~~~~~~~~~~~~~~~~~
  550. * Support for GEOS 3.1 and GDAL 1.6 has been dropped.
  551. * Support for SpatiaLite < 2.4 has been dropped.
  552. * GIS-specific lookups have been refactored to use the
  553. :class:`django.db.models.Lookup` API.
  554. * The default ``str`` representation of
  555. :class:`~django.contrib.gis.geos.GEOSGeometry` objects has been changed from
  556. WKT to EWKT format (including the SRID). As this representation is used in
  557. the serialization framework, that means that ``dumpdata`` output will now
  558. contain the SRID value of geometry objects.
  559. Priority of context processors for ``TemplateResponse`` brought in line with ``render``
  560. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  561. The :class:`~django.template.response.TemplateResponse` constructor is designed to be a
  562. drop-in replacement for the :func:`~django.shortcuts.render` function. However,
  563. it had a slight incompatibility, in that for ``TemplateResponse``, context data
  564. from the passed in context dictionary could be shadowed by context data returned
  565. from context processors, whereas for ``render`` it was the other way
  566. around. This was a bug, and the behavior of ``render`` is more appropriate,
  567. since it allows the globally defined context processors to be overridden locally
  568. in the view. If you were relying on the fact context data in a
  569. ``TemplateResponse`` could be overridden using a context processor, you will
  570. need to change your code.
  571. Overriding ``setUpClass`` / ``tearDownClass`` in test cases
  572. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  573. The decorators :func:`~django.test.override_settings` and
  574. :func:`~django.test.modify_settings` now act at the class level when used as
  575. class decorators. As a consequence, when overriding ``setUpClass()`` or
  576. ``tearDownClass()``, the ``super`` implementation should always be called.
  577. Removal of ``django.contrib.formtools``
  578. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  579. The formtools contrib app has been moved into a separate package.
  580. ``django.contrib.formtools`` itself has been removed. The docs provide
  581. :ref:`migration instructions <formtools-how-to-migrate>`.
  582. The new package is available `on Github`_ and on PyPI.
  583. .. _on GitHub: https://github.com/django/django-formtools/
  584. Database connection reloading between tests
  585. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  586. Django previously closed database connections between each test within a
  587. ``TestCase``. This is no longer the case as Django now wraps the whole
  588. ``TestCase`` within a transaction. If some of your tests relied on the old
  589. behavior, you should have them inherit from ``TransactionTestCase`` instead.
  590. Miscellaneous
  591. ~~~~~~~~~~~~~
  592. * ``connections.queries`` is now a read-only attribute.
  593. * Database connections are considered equal only if they're the same object.
  594. They aren't hashable any more.
  595. * :class:`~django.middleware.gzip.GZipMiddleware` used to disable compression
  596. for some content types when the request is from Internet Explorer, in order
  597. to work around a bug in IE6 and earlier. This behavior could affect
  598. performance on IE7 and later. It was removed.
  599. * ``URLField.to_python`` no longer adds a trailing slash to pathless URLs.
  600. * The :tfilter:`length` template filter now returns ``0`` for an undefined
  601. variable, rather than an empty string.
  602. * ``ForeignKey.default_error_message['invalid']`` has been changed from
  603. ``'%(model)s instance with pk %(pk)r does not exist.'`` to
  604. ``'%(model)s instance with %(field)s %(value)r does not exist.'`` If you are
  605. using this message in your own code, please update the list of interpolated
  606. parameters. Internally, Django will continue to provide the
  607. ``pk`` parameter in ``params`` for backwards compatibility.
  608. * ``UserCreationForm.errors_messages['duplicate_username']`` is no longer used.
  609. If you wish to customize that error message, :ref:`override it on the form
  610. <modelforms-overriding-default-fields>` using the ``'unique'`` key in
  611. ``Meta.errors_messages['username']`` or, if you have a custom form field for
  612. ``'username'``, using the the ``'unique'`` key in its
  613. :attr:`~django.forms.Field.error_messages` argument.
  614. * ``AdminSite`` no longer takes an ``app_name`` argument and its ``app_name``
  615. attribute has been removed. The application name is always ``admin`` (as
  616. opposed to the instance name which you can still customize using
  617. ``AdminSite(name="...")``.
  618. * Internal changes were made to the :class:`~django.forms.ClearableFileInput`
  619. widget to allow more customization. The undocumented ``url_markup_template``
  620. attribute was removed in favor of ``template_with_initial``.
  621. * For consistency with other major vendors, the ``en_GB`` locale now has Monday
  622. as the first day of the week.
  623. * Seconds have been removed from any locales that had them in ``TIME_FORMAT``,
  624. ``DATETIME_FORMAT``, or ``SHORT_DATETIME_FORMAT``.
  625. * The default max size of the Oracle test tablespace has increased from 300M
  626. (or 200M, before 1.7.2) to 500M.
  627. * :func:`~django.core.urlresolvers.reverse` and
  628. :func:`~django.core.urlresolvers.reverse_lazy` now return Unicode strings
  629. instead of byte strings.
  630. * The ``CacheClass`` shim has been removed from all cache backends.
  631. These aliases were provided for backwards compatibility with Django 1.3.
  632. If you are still using them, please update your project to use the real
  633. class name found in the :setting:`BACKEND <CACHES-BACKEND>` key of the
  634. :setting:`CACHES` setting.
  635. * By default, :ref:`call_command <call-command>` now always skips the check
  636. framework (unless you pass it ``skip_checks=False``).
  637. * When iterating over lines, :class:`~django.core.files.File` now uses
  638. `universal newlines`_. The following are recognized as ending a line: the
  639. Unix end-of-line convention ``'\n'``, the Windows convention ``'\r\n'``, and
  640. the old Macintosh convention ``'\r'``.
  641. .. _universal newlines: https://www.python.org/dev/peps/pep-0278
  642. * The Memcached cache backends ``MemcachedCache`` and ``PyLibMCCache`` will
  643. delete a key if ``set()`` fails. This is necessary to ensure the ``cache_db``
  644. session store always fetches the most current session data.
  645. * Private API ``django.template.compile_string`` was removed.
  646. * Private APIs ``override_template_loaders`` and ``override_with_test_loader``
  647. in ``django.test.utils`` were removed. Override ``TEMPLATE_LOADERS`` with
  648. ``override_settings`` instead.
  649. * Warnings from the MySQL database backend are no longer converted to
  650. exceptions when :setting:`DEBUG` is ``True``.
  651. * :class:`~django.http.HttpRequest` now has a simplified ``repr`` (e.g.
  652. ``<WSGIRequest: GET '/somepath/'>``). This won't change the behavior of
  653. the :class:`~django.views.debug.SafeExceptionReporterFilter` class.
  654. * Class-based views that use :class:`~django.views.generic.edit.ModelFormMixin`
  655. will raise an :exc:`~django.core.exceptions.ImproperlyConfigured` exception
  656. when both the ``fields`` and ``form_class`` attributes are specified.
  657. Previously, ``fields`` was silently ignored.
  658. * When following redirects, the test client now raises
  659. :exc:`~django.test.client.RedirectCycleError` if it detects a loop or hits a
  660. maximum redirect limit (rather than passing silently).
  661. * Translatable strings set as the ``default`` parameter of the field are cast
  662. to concrete strings later, so the return type of ``Field.get_default()`` is
  663. different in some cases. There is no change to default values which are the
  664. result of a callable.
  665. .. _deprecated-features-1.8:
  666. Features deprecated in 1.8
  667. ==========================
  668. Loading ``cycle`` and ``firstof`` template tags from ``future`` library
  669. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  670. Django 1.6 introduced ``{% load cycle from future %}`` and
  671. ``{% load firstof from future %}`` syntax for forward compatibility of the
  672. :ttag:`cycle` and :ttag:`firstof` template tags. This syntax is now deprecated
  673. and will be removed in Django 2.0. You can simply remove the
  674. ``{% load ... from future %}`` tags.
  675. ``django.conf.urls.patterns()``
  676. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  677. In the olden days of Django, it was encouraged to reference views as strings
  678. in ``urlpatterns``::
  679. urlpatterns = patterns('',
  680. url('^$', 'myapp.views.myview'),
  681. )
  682. and Django would magically import ``myapp.views.myview`` internally and turn
  683. the string into a real function reference. In order to reduce repetition when
  684. referencing many views from the same module, the ``patterns()`` function takes
  685. a required initial ``prefix`` argument which is prepended to all
  686. views-as-strings in that set of ``urlpatterns``::
  687. urlpatterns = patterns('myapp.views',
  688. url('^$', 'myview'),
  689. url('^other/$', 'otherview'),
  690. )
  691. In the modern era, we have updated the tutorial to instead recommend importing
  692. your views module and referencing your view functions (or classes) directly.
  693. This has a number of advantages, all deriving from the fact that we are using
  694. normal Python in place of "Django String Magic": the errors when you mistype a
  695. view name are less obscure, IDEs can help with autocompletion of view names,
  696. etc.
  697. So these days, the above use of the ``prefix`` arg is much more likely to be
  698. written (and is better written) as::
  699. from myapp import views
  700. urlpatterns = patterns('',
  701. url('^$', views.myview),
  702. url('^other/$', views.otherview),
  703. )
  704. Thus ``patterns()`` serves little purpose and is a burden when teaching new users
  705. (answering the newbie's question "why do I need this empty string as the first
  706. argument to ``patterns()``?"). For these reasons, we are deprecating it.
  707. Updating your code is as simple as ensuring that ``urlpatterns`` is a list of
  708. :func:`django.conf.urls.url` instances. For example::
  709. from django.conf.urls import url
  710. from myapp import views
  711. urlpatterns = [
  712. url('^$', views.myview),
  713. url('^other/$', views.otherview),
  714. ]
  715. Passing a string as ``view`` to :func:`~django.conf.urls.url`
  716. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  717. Related to the previous item, referencing views as strings in the ``url()``
  718. function is deprecated. Pass the callable view as described in the previous
  719. section instead.
  720. ``django.test.SimpleTestCase.urls``
  721. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  722. The attribute :attr:`SimpleTestCase.urls <django.test.SimpleTestCase.urls>`
  723. for specifying URLconf configuration in tests has been deprecated and will be
  724. removed in Django 2.0. Use :func:`@override_settings(ROOT_URLCONF=...)
  725. <django.test.override_settings>` instead.
  726. ``prefix`` argument to :func:`~django.conf.urls.i18n.i18n_patterns`
  727. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  728. Related to the previous item, the ``prefix`` argument to
  729. :func:`django.conf.urls.i18n.i18n_patterns` has been deprecated. Simply pass a
  730. list of :func:`django.conf.urls.url` instances instead.
  731. Using an incorrect count of unpacked values in the :ttag:`for` template tag
  732. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  733. Using an incorrect count of unpacked values in :ttag:`for` tag will raise an
  734. exception rather than fail silently in Django 2.0.
  735. Passing a dotted path to :func:`~django.core.urlresolvers.reverse()` and :ttag:`url`
  736. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  737. Reversing URLs by Python path is an expensive operation as it causes the
  738. path being reversed to be imported. This behavior has also resulted in a
  739. `security issue`_. Use :ref:`named URL patterns <naming-url-patterns>`
  740. for reversing instead.
  741. If you are using :mod:`django.contrib.sitemaps`, add the ``name`` argument to
  742. the ``url`` that references :func:`django.contrib.sitemaps.views.sitemap`::
  743. from django.contrib.sitemaps.views import sitemap
  744. url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
  745. name='django.contrib.sitemaps.views.sitemap')
  746. to ensure compatibility when reversing by Python path is removed in Django 2.0.
  747. Similarly for GIS sitemaps, add ``name='django.contrib.gis.sitemaps.views.kml'``
  748. or ``name='django.contrib.gis.sitemaps.views.kmz'``.
  749. .. _security issue: https://www.djangoproject.com/weblog/2014/apr/21/security/#s-issue-unexpected-code-execution-using-reverse
  750. Aggregate methods and modules
  751. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  752. The ``django.db.models.sql.aggregates`` and
  753. ``django.contrib.gis.db.models.sql.aggregates`` modules (both private API), have
  754. been deprecated as ``django.db.models.aggregates`` and
  755. ``django.contrib.gis.db.models.aggregates`` are now also responsible
  756. for SQL generation. The old modules will be removed in Django 2.0.
  757. If you were using the old modules, see :doc:`Query Expressions
  758. </ref/models/expressions>` for instructions on rewriting custom aggregates
  759. using the new stable API.
  760. The following methods and properties of ``django.db.models.sql.query.Query``
  761. have also been deprecated and the backwards compatibility shims will be removed
  762. in Django 2.0:
  763. * ``Query.aggregates``, replaced by ``annotations``.
  764. * ``Query.aggregate_select``, replaced by ``annotation_select``.
  765. * ``Query.add_aggregate()``, replaced by ``add_annotation()``.
  766. * ``Query.set_aggregate_mask()``, replaced by ``set_annotation_mask()``.
  767. * ``Query.append_aggregate_mask()``, replaced by ``append_annotation_mask()``.
  768. Extending management command arguments through ``Command.option_list``
  769. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  770. Management commands now use :py:mod:`argparse` instead of :py:mod:`optparse` to
  771. parse command-line arguments passed to commands. This also means that the way
  772. to add custom arguments to commands has changed: instead of extending the
  773. ``option_list`` class list, you should now override the
  774. :meth:`~django.core.management.BaseCommand.add_arguments` method and add
  775. arguments through ``argparse.add_argument()``. See
  776. :ref:`this example <custom-commands-options>` for more details.
  777. ``django.core.management.NoArgsCommand``
  778. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  779. The class :class:`~django.core.management.NoArgsCommand` is now deprecated and
  780. will be removed in Django 2.0. Use :class:`~django.core.management.BaseCommand`
  781. instead, which takes no arguments by default.
  782. ``cache_choices`` option of ``ModelChoiceField`` and ``ModelMultipleChoiceField``
  783. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  784. :class:`~django.forms.ModelChoiceField` and
  785. :class:`~django.forms.ModelMultipleChoiceField` took an undocumented, untested
  786. option ``cache_choices``. This cached querysets between multiple renderings of
  787. the same ``Form`` object. This option is subject to an accelerated deprecation
  788. and will be removed in Django 1.9.
  789. ``django.template.resolve_variable()``
  790. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  791. The function has been informally marked as "Deprecated" for some time. Replace
  792. ``resolve_variable(path, context)`` with
  793. ``django.template.Variable(path).resolve(context)``.
  794. ``django.contrib.webdesign``
  795. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  796. It provided the :ttag:`lorem` template tag which is now included in the
  797. built-in tags. Simply remove ``'django.contrib.webdesign'`` from
  798. :setting:`INSTALLED_APPS` and ``{% load webdesign %}`` from your templates.
  799. ``error_message`` argument to ``django.forms.RegexField``
  800. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  801. It provided backwards compatibility for pre-1.0 code, but its functionality is
  802. redundant. Use ``Field.error_messages['invalid']`` instead.
  803. Old :tfilter:`unordered_list` syntax
  804. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  805. An older (pre-1.0), more restrictive and verbose input format for the
  806. :tfilter:`unordered_list` template filter has been deprecated::
  807. ``['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]``
  808. Using the new syntax, this becomes::
  809. ``['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]``
  810. ``django.forms.Field._has_changed()``
  811. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  812. Rename this method to :meth:`~django.forms.Field.has_changed` by removing the
  813. leading underscore. The old name will still work until Django 2.0.
  814. ``django.utils.html.remove_tags()`` and ``removetags`` template filter
  815. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  816. ``django.utils.html.remove_tags()`` as well as the template filter
  817. ``removetags`` have been deprecated as they cannot guarantee safe output. Their
  818. existence is likely to lead to their use in security-sensitive contexts where
  819. they are not actually safe.
  820. The unused and undocumented ``django.utils.html.strip_entities()`` function has
  821. also been deprecated.
  822. ``is_admin_site`` argument to ``django.contrib.auth.views.password_reset()``
  823. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  824. It's a legacy option that should no longer be necessary.
  825. ``SubfieldBase``
  826. ~~~~~~~~~~~~~~~~
  827. ``django.db.models.fields.subclassing.SubfieldBase`` has been deprecated and
  828. will be removed in Django 2.0. Historically, it was used to handle fields where
  829. type conversion was needed when loading from the database, but it was not used
  830. in ``.values()`` calls or in aggregates. It has been replaced with
  831. :meth:`~django.db.models.Field.from_db_value`. Note that the new approach does
  832. not call the :meth:`~django.db.models.Field.to_python` method on assignment
  833. as was the case with ``SubfieldBase``.
  834. ``django.utils.checksums``
  835. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  836. The ``django.utils.checksums`` module has been deprecated and will be removed
  837. in Django 2.0. The functionality it provided (validating checksum using the
  838. Luhn algorithm) was undocumented and not used in Django. The module has been
  839. moved to the `django-localflavor`_ package (version 1.1+).
  840. .. _django-localflavor: https://pypi.python.org/pypi/django-localflavor
  841. ``django.contrib.admin.helpers.InlineAdminForm.original_content_type_id``
  842. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  843. The ``original_content_type_id`` attribute on ``InlineAdminForm`` has been
  844. deprecated and will be removed in Django 2.0. Historically, it was used
  845. to construct the "view on site" URL. This URL is now accessible using the
  846. ``absolute_url`` attribute of the form.
  847. ``django.views.generic.edit.FormMixin.get_form()``’s ``form_class`` argument
  848. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  849. ``FormMixin`` subclasses that override the ``get_form()`` method should make
  850. sure to provide a default value for the ``form_class`` argument since it's
  851. now optional.
  852. ``dirs`` argument of template-finding functions
  853. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  854. The following functions will no longer accept a ``dirs`` parameter to override
  855. :setting:`TEMPLATE_DIRS` in Django 2.0:
  856. * :func:`django.template.loader.get_template()`
  857. * :func:`django.template.loader.select_template()`
  858. * :func:`django.shortcuts.render()`
  859. * :func:`django.shortcuts.render_to_response()`
  860. The parameter didn't work consistently across different template loaders and
  861. didn't work for included templates.
  862. ``django.template.loader.BaseLoader``
  863. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  864. ``django.template.loader.BaseLoader`` was renamed to
  865. ``django.template.loaders.base.Loader``. If you've written a custom template
  866. loader that inherits ``BaseLoader``, you must inherit ``Loader`` instead.
  867. ``django.test.utils.TestTemplateLoader``
  868. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  869. Private API ``django.test.utils.TestTemplateLoader`` is deprecated in favor of
  870. ``django.template.loaders.locmem.Loader``.
  871. ``qn`` replaced by ``compiler``
  872. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  873. In previous Django versions, various internal ORM methods (mostly ``as_sql``
  874. methods) accepted a ``qn`` (for "quote name") argument, which was a reference
  875. to a function that quoted identifiers for sending to the database. In Django
  876. 1.8, that argument has been renamed to ``compiler`` and is now a full
  877. ``SQLCompiler`` instance. For backwards-compatibility, calling a
  878. ``SQLCompiler`` instance performs the same name-quoting that the ``qn``
  879. function used to. However, this backwards-compatibility shim is immediately
  880. deprecated: you should rename your ``qn`` arguments to ``compiler``, and call
  881. ``compiler.quote_name_unless_alias(...)`` where you previously called
  882. ``qn(...)``.
  883. Default value of ``RedirectView.permanent``
  884. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  885. The default value of the
  886. :attr:`RedirectView.permanent <django.views.generic.base.RedirectView.permanent>`
  887. attribute will change from ``True`` to ``False`` in Django 1.9.
  888. Using ``AuthenticationMiddleware`` without ``SessionAuthenticationMiddleware``
  889. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  890. :class:`django.contrib.auth.middleware.SessionAuthenticationMiddleware` was
  891. added in Django 1.7. In Django 1.7.2, its functionality was moved to
  892. ``auth.get_user()`` and, for backwards compatibility, enabled only if
  893. ``'django.contrib.auth.middleware.SessionAuthenticationMiddleware'`` appears in
  894. :setting:`MIDDLEWARE_CLASSES`.
  895. In Django 2.0, session verification will be enabled regardless of whether or not
  896. ``SessionAuthenticationMiddleware`` is enabled (at which point
  897. ``SessionAuthenticationMiddleware`` will have no significance). You can add it
  898. to your ``MIDDLEWARE_CLASSES`` sometime before then to opt-in. Please read the
  899. :ref:`upgrade considerations <session-invalidation-on-password-change>` first.
  900. ``django.contrib.sitemaps.FlatPageSitemap``
  901. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  902. ``django.contrib.sitemaps.FlatPageSitemap`` has moved to
  903. ``django.contrib.flatpages.sitemaps.FlatPageSitemap``. The old import location
  904. is deprecated and will be removed in Django 1.9.
  905. .. removed-features-1.8:
  906. Features removed in 1.8
  907. =======================
  908. These features have reached the end of their deprecation cycle and so have been
  909. removed in Django 1.8 (please see the :ref:`deprecation timeline
  910. <deprecation-removed-in-1.8>` for more details):
  911. * ``django.contrib.comments`` is removed.
  912. * The following transaction management APIs are removed:
  913. - ``TransactionMiddleware``
  914. - the decorators and context managers ``autocommit``, ``commit_on_success``,
  915. and ``commit_manually``, defined in ``django.db.transaction``
  916. - the functions ``commit_unless_managed`` and ``rollback_unless_managed``,
  917. also defined in ``django.db.transaction``
  918. - the ``TRANSACTIONS_MANAGED`` setting
  919. * The :ttag:`cycle` and :ttag:`firstof` template tags auto-escape their
  920. arguments.
  921. * The ``SEND_BROKEN_LINK_EMAILS`` setting is removed.
  922. * ``django.middleware.doc.XViewMiddleware`` is removed.
  923. * The ``Model._meta.module_name`` alias is removed.
  924. * The backward compatible shims introduced to rename ``get_query_set``
  925. and similar queryset methods are removed. This affects the following classes:
  926. ``BaseModelAdmin``, ``ChangeList``, ``BaseCommentNode``,
  927. ``GenericForeignKey``, ``Manager``, ``SingleRelatedObjectDescriptor`` and
  928. ``ReverseSingleRelatedObjectDescriptor``.
  929. * The backward compatible shims introduced to rename the attributes
  930. ``ChangeList.root_query_set`` and ``ChangeList.query_set`` are removed.
  931. * ``django.views.defaults.shortcut`` and ``django.conf.urls.shortcut`` are
  932. removed.
  933. * Support for the Python Imaging Library (PIL) module is removed.
  934. * The following private APIs are removed:
  935. - ``django.db.backend``
  936. - ``django.db.close_connection()``
  937. - ``django.db.backends.creation.BaseDatabaseCreation.set_autocommit()``
  938. - ``django.db.transaction.is_managed()``
  939. - ``django.db.transaction.managed()``
  940. * ``django.forms.widgets.RadioInput`` is removed.
  941. * The module ``django.test.simple`` and the class
  942. ``django.test.simple.DjangoTestSuiteRunner`` are removed.
  943. * The module ``django.test._doctest`` is removed.
  944. * The ``CACHE_MIDDLEWARE_ANONYMOUS_ONLY`` setting is removed.
  945. * Usage of the hard-coded *Hold down "Control", or "Command" on a Mac, to select
  946. more than one.* string to override or append to user-provided ``help_text`` in
  947. forms for ``ManyToMany`` model fields is not be performed by Django anymore
  948. either at the model or forms layer.
  949. * The ``Model._meta.get_(add|change|delete)_permission`` methods are removed.
  950. * The session key ``django_language`` is no longer read for backwards
  951. compatibility.
  952. * Geographic Sitemaps are removed
  953. (``django.contrib.gis.sitemaps.views.index`` and
  954. ``django.contrib.gis.sitemaps.views.sitemap``).
  955. * ``django.utils.html.fix_ampersands``, the ``fix_ampersands`` template filter,
  956. and ``django.utils.html.clean_html`` are removed.