1.8.txt 54 KB

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