1.6.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. ============================================
  2. Django 1.6 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. Welcome to Django 1.6!
  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.5 or older versions. We've also dropped some features, which are detailed in
  8. :doc:`our deprecation plan </internals/deprecation>`, and we've `begun the
  9. deprecation process for some features`_.
  10. .. _`new features`: `What's new in Django 1.6`_
  11. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.6`_
  12. .. _`begun the deprecation process for some features`: `Features deprecated in 1.6`_
  13. What's new in Django 1.6
  14. ========================
  15. Simplified default project and app templates
  16. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  17. The default templates used by :djadmin:`startproject` and :djadmin:`startapp`
  18. have been simplified and modernized. The :doc:`admin
  19. </ref/contrib/admin/index>` is now enabled by default in new projects; the
  20. :doc:`sites </ref/contrib/sites>` framework no longer is. :ref:`Language
  21. detection <how-django-discovers-language-preference>` and :ref:`clickjacking
  22. prevention <clickjacking-prevention>` are turned on.
  23. If the default templates don't suit your tastes, you can use :ref:`custom
  24. project and app templates <custom-app-and-project-templates>`.
  25. Persistent database connections
  26. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. Django now supports reusing the same database connection for several requests.
  28. This avoids the overhead of re-establishing a connection at the beginning of
  29. each request.
  30. By default, database connections will kept open for 10 minutes. This behavior
  31. is controlled by the :setting:`CONN_MAX_AGE` setting. To restore the previous
  32. behavior of closing the connection at the end of each request, set
  33. :setting:`CONN_MAX_AGE` to ``0``. See :ref:`persistent-database-connections`
  34. for details.
  35. Time zone aware aggregation
  36. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. The support for :doc:`time zones </topics/i18n/timezones>` introduced in
  38. Django 1.4 didn't work well with :meth:`QuerySet.dates()
  39. <django.db.models.query.QuerySet.dates>`: aggregation was always performed in
  40. UTC. This limitation was lifted in Django 1.6. Use :meth:`QuerySet.datetimes()
  41. <django.db.models.query.QuerySet.datetimes>` to perform time zone aware
  42. aggregation on a :class:`~django.db.models.DateTimeField`.
  43. ``BinaryField`` model field
  44. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. A new :class:`django.db.models.BinaryField` model field allows to store raw
  46. binary data in the database.
  47. Minor features
  48. ~~~~~~~~~~~~~~
  49. * Authentication backends can raise ``PermissionDenied`` to immediately fail
  50. the authentication chain.
  51. * The HttpOnly flag can be set on the CSRF cookie with
  52. :setting:`CSRF_COOKIE_HTTPONLY`.
  53. * The ``assertQuerysetEqual()`` now checks for undefined order and raises
  54. ``ValueError`` if undefined order is spotted. The order is seen as
  55. undefined if the given ``QuerySet`` isn't ordered and there are more than
  56. one ordered values to compare against.
  57. * Added :meth:`~django.db.models.query.QuerySet.earliest` for symmetry with
  58. :meth:`~django.db.models.query.QuerySet.latest`.
  59. * In addition to :lookup:`year`, :lookup:`month` and :lookup:`day`, the ORM
  60. now supports :lookup:`hour`, :lookup:`minute` and :lookup:`second` lookups.
  61. * Django now wraps all PEP-249 exceptions.
  62. * The default widgets for :class:`~django.forms.EmailField`,
  63. :class:`~django.forms.URLField`, :class:`~django.forms.IntegerField`,
  64. :class:`~django.forms.FloatField` and :class:`~django.forms.DecimalField` use
  65. the new type attributes available in HTML5 (type='email', type='url',
  66. type='number'). Note that due to erratic support of the ``number`` input type
  67. with localized numbers in current browsers, Django only uses it when numeric
  68. fields are not localized.
  69. * The ``number`` argument for :ref:`lazy plural translations
  70. <lazy-plural-translations>` can be provided at translation time rather than
  71. at definition time.
  72. * For custom management commands: Verification of the presence of valid
  73. settings in commands that ask for it by using the
  74. :attr:`~django.core.management.BaseCommand.can_import_settings` internal
  75. option is now performed independently from handling of the locale that
  76. should be active during the execution of the command. The latter can now be
  77. influenced by the new
  78. :attr:`~django.core.management.BaseCommand.leave_locale_alone` internal
  79. option. See :ref:`management-commands-and-locales` for more details.
  80. * The :attr:`~django.views.generic.edit.DeletionMixin.success_url` of
  81. :class:`~django.views.generic.edit.DeletionMixin` is now interpolated with
  82. its ``object``\'s ``__dict__``.
  83. * :class:`~django.http.HttpResponseRedirect` and
  84. :class:`~django.http.HttpResponsePermanentRedirect` now provide an ``url``
  85. attribute (equivalent to the URL the response will redirect to).
  86. * The ``MemcachedCache`` cache backend now uses the latest :mod:`pickle`
  87. protocol available.
  88. * Added the :attr:`django.db.models.ForeignKey.db_constraint` and
  89. :attr:`django.db.models.ManyToManyField.db_constraint` options.
  90. * The jQuery library embedded in the admin has been upgraded to version 1.9.1.
  91. * Syndication feeds (:mod:`django.contrib.syndication`) can now pass extra
  92. context through to feed templates using a new `Feed.get_context_data()`
  93. callback.
  94. * The admin list columns have a ``column-<field_name>`` class in the HTML
  95. so the columns header can be styled with CSS, e.g. to set a column width.
  96. * The isolation level can be customized under PostgreSQL.
  97. * The :ttag:`blocktrans` template tag now respects
  98. :setting:`TEMPLATE_STRING_IF_INVALID` for variables not present in the
  99. context, just like other template constructs.
  100. * SimpleLazyObjects will now present more helpful representations in shell
  101. debugging situations.
  102. Backwards incompatible changes in 1.6
  103. =====================================
  104. * The ``django.db.models.query.EmptyQuerySet`` can't be instantiated any more -
  105. it is only usable as a marker class for checking if
  106. :meth:`~django.db.models.query.QuerySet.none` has been called:
  107. ``isinstance(qs.none(), EmptyQuerySet)``
  108. * :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` raises an
  109. error if it's used on :class:`~django.db.models.DateTimeField` when time
  110. zone support is active. Use :meth:`QuerySet.datetimes()
  111. <django.db.models.query.QuerySet.datetimes>` instead.
  112. * :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` returns a
  113. list of :class:`~datetime.date`. It used to return a list of
  114. :class:`~datetime.datetime`.
  115. * The :attr:`~django.contrib.admin.ModelAdmin.date_hierarchy` feature of the
  116. admin on a :class:`~django.db.models.DateTimeField` requires time zone
  117. definitions in the database when :setting:`USE_TZ` is ``True``.
  118. :ref:`Learn more <database-time-zone-definitions>`.
  119. * Accessing ``date_list`` in the context of a date-based generic view requires
  120. time zone definitions in the database when the view is based on a
  121. :class:`~django.db.models.DateTimeField` and :setting:`USE_TZ` is ``True``.
  122. :ref:`Learn more <database-time-zone-definitions>`.
  123. * Model fields named ``hour``, ``minute`` or ``second`` may clash with the new
  124. lookups. Append an explicit :lookup:`exact` lookup if this is an issue.
  125. * When Django establishes a connection to the database, it sets up appropriate
  126. parameters, depending on the backend being used. Since `persistent database
  127. connections <persistent-database-connections>`_ are enabled by default in
  128. Django 1.6, this setup isn't repeated at every request any more. If you
  129. modifiy parameters such as the connection's isolation level or time zone,
  130. you should either restore Django's defaults at the end of each request, or
  131. force an appropriate value at the beginning of each request.
  132. * If your CSS/Javascript code used to access HTML input widgets by type, you
  133. should review it as ``type='text'`` widgets might be now output as
  134. ``type='email'``, ``type='url'`` or ``type='number'`` depending on their
  135. corresponding field type.
  136. * Extraction of translatable literals from templates with the
  137. :djadmin:`makemessages` command now correctly detects i18n constructs when
  138. they are located after a ``{#`` / ``#}``-type comment on the same line. E.g.:
  139. .. code-block:: html+django
  140. {# A comment #}{% trans "This literal was incorrectly ignored. Not anymore" %}
  141. * (Related to the above item.) Validation of the placement of
  142. :ref:`translator-comments-in-templates` specified using ``{#`` / ``#}`` is now
  143. stricter. All translator comments not located at the end of their respective
  144. lines in a template are ignored and a warning is generated by
  145. :djadmin:`makemessages` when it finds them. E.g.:
  146. .. code-block:: html+django
  147. {# Translators: This is ignored #}{% trans "Translate me" %}
  148. {{ title }}{# Translators: Extracted and associated with 'Welcome' below #}
  149. <h1>{% trans "Welcome" %}</h1>
  150. * The :doc:`comments </ref/contrib/comments/index>` app now uses a ``GenericIPAddressField``
  151. for storing commenters' IP addresses, to support comments submitted from IPv6 addresses.
  152. Until now, it stored them in an ``IPAddressField``, which is only meant to support IPv4.
  153. When saving a comment made from an IPv6 address, the address would be silently truncated
  154. on MySQL databases, and raise an exception on Oracle.
  155. You will need to change the column type in your database to benefit from this change.
  156. For MySQL, execute this query on your project's database:
  157. .. code-block:: sql
  158. ALTER TABLE django_comments MODIFY ip_address VARCHAR(39);
  159. For Oracle, execute this query:
  160. .. code-block:: sql
  161. ALTER TABLE DJANGO_COMMENTS MODIFY (ip_address VARCHAR2(39));
  162. If you do not apply this change, the behaviour is unchanged: on MySQL, IPv6 addresses
  163. are silently truncated; on Oracle, an exception is generated. No database
  164. change is needed for SQLite or PostgreSQL databases.
  165. .. warning::
  166. In addition to the changes outlined in this section, be sure to review the
  167. :doc:`deprecation plan </internals/deprecation>` for any features that
  168. have been removed. If you haven't updated your code within the
  169. deprecation timeline for a given feature, its removal may appear as a
  170. backwards incompatible change.
  171. Features deprecated in 1.6
  172. ==========================
  173. Changes to :ttag:`cycle` and :ttag:`firstof`
  174. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  175. The template system generally escapes all variables to avoid XSS attacks.
  176. However, due to an accident of history, the :ttag:`cycle` and :ttag:`firstof`
  177. tags render their arguments as-is.
  178. Django 1.6 starts a process to correct this inconsistency. The ``future``
  179. template library provides alternate implementations of :ttag:`cycle` and
  180. :ttag:`firstof` that autoescape their inputs. If you're using these tags,
  181. you're encourage to include the following line at the top of your templates to
  182. enable the new behavior::
  183. {% load cycle from future %}
  184. or::
  185. {% load firstof from future %}
  186. The tags implementing the old behavior have been deprecated, and in Django
  187. 1.8, the old behavior will be replaced with the new behavior. To ensure
  188. compatibility with future versions of Django, existing templates should be
  189. modified to use the ``future`` versions.
  190. If necessary, you can temporarily disable auto-escaping with
  191. :func:`~django.utils.safestring.mark_safe` or :ttag:`{% autoescape off %}
  192. <autoescape>`.
  193. ``SEND_BROKEN_LINK_EMAILS`` setting
  194. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  195. :class:`~django.middleware.common.CommonMiddleware` used to provide basic
  196. reporting of broken links by email when ``SEND_BROKEN_LINK_EMAILS`` is set to
  197. ``True``.
  198. Because of intractable ordering problems between
  199. :class:`~django.middleware.common.CommonMiddleware` and
  200. :class:`~django.middleware.locale.LocaleMiddleware`, this feature was split
  201. out into a new middleware:
  202. :class:`~django.middleware.common.BrokenLinkEmailsMiddleware`.
  203. If you're relying on this feature, you should add
  204. ``'django.middleware.common.BrokenLinkEmailsMiddleware'`` to your
  205. :setting:`MIDDLEWARE_CLASSES` setting and remove ``SEND_BROKEN_LINK_EMAILS``
  206. from your settings.
  207. ``_has_changed`` method on widgets
  208. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209. If you defined your own form widgets and defined the ``_has_changed`` method
  210. on a widget, you should now define this method on the form field itself.
  211. ``module_name`` model meta attribute
  212. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  213. ``Model._meta.module_name`` was renamed to ``model_name``. Despite being a
  214. private API, it will go through a regular deprecation path.
  215. ``get_query_set`` and similar methods renamed to ``get_queryset``
  216. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  217. Methods that return a ``QuerySet`` such as ``Manager.get_query_set`` or
  218. ``ModelAdmin.queryset`` have been renamed to ``get_queryset``.