1.8.txt 53 KB

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