1.8.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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 dropped some features, which are detailed in
  8. :ref:`our deprecation plan <deprecation-removed-in-1.8>`, and we've `begun the
  9. deprecation process for some features`_.
  10. .. _`new features`: `What's new in Django 1.8`_
  11. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.8`_
  12. .. _`begun the deprecation process for some features`: `Features deprecated in 1.8`_
  13. Python compatibility
  14. ====================
  15. Like Django 1.7, Django 1.8 requires Python 2.7 or above, though we
  16. **highly recommend** the latest minor release.
  17. What's new in Django 1.8
  18. ========================
  19. ...
  20. Minor features
  21. ~~~~~~~~~~~~~~
  22. :mod:`django.contrib.admin`
  23. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  24. * :class:`~django.contrib.admin.ModelAdmin` now has a
  25. :meth:`~django.contrib.admin.ModelAdmin.has_module_permission`
  26. method to allow limiting access to the module on the admin index page.
  27. :mod:`django.contrib.auth`
  28. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  29. * Authorization backends can now raise
  30. :class:`~django.core.exceptions.PermissionDenied` in
  31. :meth:`~django.contrib.auth.models.User.has_perm`
  32. and :meth:`~django.contrib.auth.models.User.has_module_perms`
  33. to short-circuit permission checking.
  34. * :class:`~django.contrib.auth.forms.PasswordResetForm` now
  35. has a method :meth:`~django.contrib.auth.forms.PasswordResetForm.send_email`
  36. that can be overridden to customize the mail to be sent.
  37. :mod:`django.contrib.formtools`
  38. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  39. * A :doc:`form wizard </ref/contrib/formtools/form-wizard>` using the
  40. :class:`~django.contrib.formtools.wizard.views.CookieWizardView` will now ignore
  41. an invalid cookie, and the wizard will restart from the first step. An invalid
  42. cookie can occur in cases of intentional manipulation, but also after a secret
  43. key change. Previously, this would raise ``WizardViewCookieModified``, a
  44. ``SuspiciousOperation``, causing an exception for any user with an invalid cookie
  45. upon every request to the wizard, until the cookie is removed.
  46. :mod:`django.contrib.gis`
  47. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  48. * Compatibility shims for ``SpatialRefSys`` and ``GeometryColumns`` changed in
  49. Django 1.2 have been removed.
  50. :mod:`django.contrib.messages`
  51. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  52. * ...
  53. :mod:`django.contrib.redirects`
  54. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  55. * ...
  56. :mod:`django.contrib.sessions`
  57. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  58. * Session cookie is now deleted after
  59. :meth:`~django.contrib.sessions.backends.base.SessionBase.flush()` is called.
  60. :mod:`django.contrib.sitemaps`
  61. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  62. * ...
  63. :mod:`django.contrib.sites`
  64. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  65. * ...
  66. :mod:`django.contrib.staticfiles`
  67. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  68. * ...
  69. :mod:`django.contrib.syndication`
  70. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  71. * ...
  72. Cache
  73. ^^^^^
  74. * ...
  75. Email
  76. ^^^^^
  77. * :ref:`Email backends <topic-email-backends>` now support the context manager
  78. protocol for opening and closing connections.
  79. File Storage
  80. ^^^^^^^^^^^^
  81. * ...
  82. File Uploads
  83. ^^^^^^^^^^^^
  84. * ...
  85. Forms
  86. ^^^^^
  87. * Form widgets now render attributes with a value of ``True`` or ``False``
  88. as HTML5 boolean attributes.
  89. * The new :meth:`~django.forms.Form.has_error()` method allows checking
  90. if a specific error has happened.
  91. * If :attr:`~django.forms.Form.required_css_class` is defined on a form, then
  92. the ``<label>`` tags for required fields will have this class present in its
  93. attributes.
  94. * The rendering of non-field errors in unordered lists (``<ul>``) now includes
  95. ``nonfield`` in its list of classes to distinguish them from field-specific
  96. errors.
  97. * :class:`~django.forms.Field` now accepts a
  98. :attr:`~django.forms.Field.label_suffix` argument, which will override the
  99. form's :attr:`~django.forms.Form.label_suffix`. This enables customizing the
  100. suffix on a per-field basis — previously it wasn't possible to override
  101. a form's :attr:`~django.forms.Form.label_suffix` while using shortcuts such
  102. as ``{{ form.as_p }}`` in templates.
  103. * :class:`~django.forms.extras.widgets.SelectDateWidget` now accepts an
  104. :attr:`~django.forms.extras.widgets.SelectDateWidget.empty_label` argument, which will
  105. override the top list choice label when :class:`~django.forms.DateField` is not required.
  106. Internationalization
  107. ^^^^^^^^^^^^^^^^^^^^
  108. * :setting:`FORMAT_MODULE_PATH` can now be a list of strings representing
  109. module paths. This allows importing several format modules from different
  110. reusable apps. It also allows overriding those custom formats in your main
  111. Django project.
  112. Management Commands
  113. ^^^^^^^^^^^^^^^^^^^
  114. * :djadmin:`dumpdata` now has the option :djadminopt:`--output` which allows
  115. specifying the file to which the serialized data is written.
  116. * :djadmin:`makemessages` and :djadmin:`compilemessages` now have the option
  117. :djadminopt:`--exclude` which allows exclusion of specific locales from
  118. processing.
  119. * The :djadminopt:`--ignorenonexistent` option of the :djadmin:`loaddata`
  120. management command now ignores data for models that no longer exist.
  121. * :djadmin:`runserver` now uses daemon threads for faster reloading.
  122. Models
  123. ^^^^^^
  124. * Django now logs at most 9000 queries in ``connections.queries``, in order
  125. to prevent excessive memory usage in long-running processes in debug mode.
  126. * Pickling models and querysets across different versions of Django isn't
  127. officially supported (it may work, but there's no guarantee). An extra
  128. variable that specifies the current Django version is now added to the
  129. pickled state of models and querysets, and Django raises a ``RuntimeWarning``
  130. when these objects are unpickled in a different version than the one in
  131. which they were pickled.
  132. Signals
  133. ^^^^^^^
  134. * Exceptions from the ``(receiver, exception)`` tuples returned by
  135. :meth:`Signal.send_robust() <django.dispatch.Signal.send_robust>` now have
  136. their traceback attached as a ``__traceback__`` attribute.
  137. Templates
  138. ^^^^^^^^^
  139. * ...
  140. Requests and Responses
  141. ^^^^^^^^^^^^^^^^^^^^^^
  142. * ``WSGIRequest`` now respects paths starting with ``//``.
  143. * The :meth:`HttpRequest.build_absolute_uri()
  144. <django.http.HttpRequest.build_absolute_uri>` method now handles paths
  145. starting with ``//`` correctly.
  146. Tests
  147. ^^^^^
  148. * The ``count`` argument was added to
  149. :meth:`~django.test.SimpleTestCase.assertTemplateUsed`. This allows you to
  150. assert that a template was rendered a specific number of times.
  151. * The new :meth:`~django.test.SimpleTestCase.assertJSONNotEqual` assertion
  152. allows you to test that two JSON fragments are not equal.
  153. * Added the ability to preserve the test database by adding the
  154. :djadminopt:`--keepdb` flag.
  155. * Added the :attr:`~django.test.Response.resolver_match` attribute to test
  156. client responses.
  157. Validators
  158. ^^^^^^^^^^
  159. * ...
  160. Backwards incompatible changes in 1.8
  161. =====================================
  162. .. warning::
  163. In addition to the changes outlined in this section, be sure to review the
  164. :ref:`deprecation plan <deprecation-removed-in-1.8>` for any features that
  165. have been removed. If you haven't updated your code within the
  166. deprecation timeline for a given feature, its removal may appear as a
  167. backwards incompatible change.
  168. Related object operations are run in a transaction
  169. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170. Some operations on related objects such as
  171. :meth:`~django.db.models.fields.related.RelatedManager.add()` or
  172. :ref:`direct assignment<direct-assignment>` ran multiple data modifying
  173. queries without wrapping them in transactions. To reduce the risk of data
  174. corruption, all data modifying methods that affect multiple related objects
  175. (i.e. ``add()``, ``remove()``, ``clear()``, and :ref:`direct assignment
  176. <direct-assignment>`) now perform their data modifying queries from within a
  177. transaction, provided your database supports transactions.
  178. This has one backwards incompatible side effect, signal handlers triggered from
  179. these methods are now executed within the method's transaction and any
  180. exception in a signal handler will prevent the whole operation.
  181. Unassigning unsaved objects to relations raises an error
  182. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  183. Assigning unsaved objects to a :class:`~django.db.models.ForeignKey`,
  184. :class:`~django.contrib.contenttypes.fields.GenericForeignKey`, and
  185. :class:`~django.db.models.OneToOneField` now raises a :exc:`ValueError`.
  186. Previously, the assignment of an unsaved object would be silently ignored.
  187. For example::
  188. >>> book = Book.objects.create(name="Django")
  189. >>> book.author = Author(name="John")
  190. >>> book.author.save()
  191. >>> book.save()
  192. >>> Book.objects.get(name="Django")
  193. >>> book.author
  194. >>>
  195. Now, an error will be raised to prevent data loss::
  196. >>> book.author = Author(name="john")
  197. Traceback (most recent call last):
  198. ...
  199. ValueError: Cannot assign "<Author: John>": "Author" instance isn't saved in the database.
  200. Management commands that only accept positional arguments
  201. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  202. If you have written a custom management command that only accepts positional
  203. arguments and you didn't specify the
  204. :attr:`~django.core.management.BaseCommand.args` command variable, you might
  205. get an error like ``Error: unrecognized arguments: ...``, as variable parsing
  206. is now based on :py:mod:`argparse` which doesn't implicitly accept positional
  207. arguments. You can make your command backwards compatible by simply setting the
  208. :attr:`~django.core.management.BaseCommand.args` class variable. However, if
  209. you don't have to keep compatibility with older Django versions, it's better to
  210. implement the new :meth:`~django.core.management.BaseCommand.add_arguments`
  211. method as described in :doc:`/howto/custom-management-commands`.
  212. Custom test management command arguments through test runner
  213. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  214. The method to add custom arguments to the `test` management command through the
  215. test runner has changed. Previously, you could provide an `option_list` class
  216. variable on the test runner to add more arguments (à la :py:mod:`optparse`).
  217. Now to implement the same behavior, you have to create an
  218. ``add_arguments(cls, parser)`` class method on the test runner and call
  219. ``parser.add_argument`` to add any custom arguments, as parser is now an
  220. :py:class:`argparse.ArgumentParser` instance.
  221. Miscellaneous
  222. ~~~~~~~~~~~~~
  223. * ``connections.queries`` is now a read-only attribute.
  224. * Database connections are considered equal only if they're the same object.
  225. They aren't hashable any more.
  226. * :class:`~django.middleware.gzip.GZipMiddleware` used to disable compression
  227. for some content types when the request is from Internet Explorer, in order
  228. to work around a bug in IE6 and earlier. This behavior could affect
  229. performance on IE7 and later. It was removed.
  230. * ``URLField.to_python`` no longer adds a trailing slash to pathless URLs.
  231. * ``django.contrib.gis`` dropped support for GEOS 3.1 and GDAL 1.6.
  232. * The :tfilter:`length` template filter now returns ``0`` for an undefined
  233. variable, rather than an empty string.
  234. * Support for SpatiaLite < 2.4 has been dropped.
  235. .. _deprecated-features-1.8:
  236. Features deprecated in 1.8
  237. ==========================
  238. Loading ``cycle`` and ``firstof`` template tags from ``future`` library
  239. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  240. Django 1.6 introduced ``{% load cycle from future %}`` and
  241. ``{% load firstof from future %}`` syntax for forward compatibility of the
  242. :ttag:`cycle` and :ttag:`firstof` template tags. This syntax is now deprecated
  243. and will be removed in Django 2.0. You can simply remove the
  244. ``{% load ... from future %}`` tags.
  245. ``django.conf.urls.patterns()``
  246. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  247. In the olden days of Django, it was encouraged to reference views as strings
  248. in ``urlpatterns``::
  249. urlpatterns = patterns('',
  250. url('^$', 'myapp.views.myview'),
  251. )
  252. and Django would magically import ``myapp.views.myview`` internally and turn
  253. the string into a real function reference. In order to reduce repetition when
  254. referencing many views from the same module, the ``patterns()`` function takes
  255. a required initial ``prefix`` argument which is prepended to all
  256. views-as-strings in that set of ``urlpatterns``::
  257. urlpatterns = patterns('myapp.views',
  258. url('^$', 'myview'),
  259. url('^other/$', 'otherview'),
  260. )
  261. In the modern era, we have updated the tutorial to instead recommend importing
  262. your views module and referencing your view functions (or classes) directly.
  263. This has a number of advantages, all deriving from the fact that we are using
  264. normal Python in place of "Django String Magic": the errors when you mistype a
  265. view name are less obscure, IDEs can help with autocompletion of view names,
  266. etc.
  267. So these days, the above use of the ``prefix`` arg is much more likely to be
  268. written (and is better written) as::
  269. from myapp import views
  270. urlpatterns = patterns('',
  271. url('^$', views.myview),
  272. url('^other/$', views.otherview),
  273. )
  274. Thus ``patterns()`` serves little purpose and is a burden when teaching new users
  275. (answering the newbie's question "why do I need this empty string as the first
  276. argument to ``patterns()``?"). For these reasons, we are deprecating it.
  277. Updating your code is as simple as ensuring that ``urlpatterns`` is a list of
  278. :func:`django.conf.urls.url` instances. For example::
  279. from django.conf.urls import url
  280. from myapp import views
  281. urlpatterns = [
  282. url('^$', views.myview),
  283. url('^other/$', views.otherview),
  284. ]
  285. ``django.test.SimpleTestCase.urls``
  286. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  287. The attribute :attr:`SimpleTestCase.urls <django.test.SimpleTestCase.urls>`
  288. for specifying URLconf configuration in tests has been deprecated and will be
  289. removed in Django 2.0. Use :func:`@override_settings(ROOT_URLCONF=...)
  290. <django.test.override_settings>` instead.
  291. ``prefix`` argument to :func:`~django.conf.urls.i18n.i18n_patterns`
  292. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  293. Related to the previous item, the ``prefix`` argument to
  294. :func:`django.conf.urls.i18n.i18n_patterns` has been deprecated. Simply pass a
  295. list of :func:`django.conf.urls.url` instances instead.
  296. Using an incorrect count of unpacked values in the :ttag:`for` template tag
  297. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  298. Using an incorrect count of unpacked values in :ttag:`for` tag will raise an
  299. exception rather than fail silently in Django 2.0.
  300. Passing a dotted path to :func:`~django.core.urlresolvers.reverse()` and :ttag:`url`
  301. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  302. Reversing URLs by Python path is an expensive operation as it causes the
  303. path being reversed to be imported. This behavior has also resulted in a
  304. `security issue`_. Use :ref:`named URL patterns <naming-url-patterns>`
  305. for reversing instead.
  306. If you are using :mod:`django.contrib.sitemaps`, add the ``name`` argument to
  307. the ``url`` that references :func:`django.contrib.sitemaps.views.sitemap`::
  308. url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap',
  309. {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap')
  310. to ensure compatibility when reversing by Python path is removed in Django 2.0.
  311. Similarly for GIS sitemaps, add ``name='django.contrib.gis.sitemaps.views.kml'``
  312. or ``name='django.contrib.gis.sitemaps.views.kmz'``.
  313. .. _security issue: https://www.djangoproject.com/weblog/2014/apr/21/security/#s-issue-unexpected-code-execution-using-reverse
  314. Extending management command arguments through ``Command.option_list``
  315. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  316. Management commands now use :py:mod:`argparse` instead of :py:mod:`optparse` to
  317. parse command-line arguments passed to commands. This also means that the way
  318. to add custom arguments to commands has changed: instead of extending the
  319. ``option_list`` class list, you should now override the
  320. :meth:`~django.core.management.BaseCommand.add_arguments` method and add
  321. arguments through ``argparse.add_argument()``. See
  322. :ref:`this example <custom-commands-options>` for more details.