1.8.txt 18 KB

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