1.4.txt 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. ============================================
  2. Django 1.4 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. This page documents release notes for the as-yet-unreleased Django
  5. 1.4. As such, it's tentative and subject to change. It provides
  6. up-to-date information for those who are following trunk.
  7. Django 1.4 includes various `new features`_ and some minor `backwards
  8. incompatible changes`_. There are also some features that have been dropped,
  9. which are detailed in :doc:`our deprecation plan </internals/deprecation>`.
  10. .. _new features: `What's new in Django 1.4`_
  11. .. _backwards incompatible changes: backwards-incompatible-changes-1.4_
  12. What's new in Django 1.4
  13. ========================
  14. ``SELECT FOR UPDATE`` support
  15. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. Django 1.4 now includes a :meth:`QuerySet.select_for_update()
  17. <django.db.models.query.QuerySet.select_for_update>` method which generates a
  18. ``SELECT ... FOR UPDATE`` SQL query. This will lock rows until the end of the
  19. transaction, meaning that other transactions cannot modify or delete rows
  20. matched by a ``FOR UPDATE`` query.
  21. For more details, see the documentation for
  22. :meth:`~django.db.models.query.QuerySet.select_for_update`.
  23. HTML5
  24. ~~~~~
  25. We've switched the admin and other bundled templates to use the HTML5
  26. doctype. While Django will be careful in its use of HTML5 features, to maintain
  27. compatibility with old browsers, this change means that you can use any HTML5
  28. features you need in admin pages without having to lose HTML validity or
  29. override the provided templates to change the doctype.
  30. List filters in admin interface
  31. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. Prior to Django 1.4, the Django admin app allowed specifying change list
  33. filters by specifying a field lookup (including spanning relations), and
  34. not custom filters. This has been rectified with a simple API previously
  35. known as "FilterSpec" which was used internally. For more details, see the
  36. documentation for :attr:`~django.contrib.admin.ModelAdmin.list_filter`.
  37. Tools for cryptographic signing
  38. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. Django 1.4 adds both a low-level API for signing values and a high-level API
  40. for setting and reading signed cookies, one of the most common uses of
  41. signing in Web applications.
  42. See :doc:`cryptographic signing </topics/signing>` docs for more information.
  43. Simple clickjacking protection
  44. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. We've added a middleware to provide easy protection against `clickjacking
  46. <http://en.wikipedia.org/wiki/Clickjacking>`_ using the X-Frame-Options
  47. header. It's not enabled by default for backwards compatibility reasons, but
  48. you'll almost certainly want to :doc:`enable it </ref/clickjacking/>` to help
  49. plug that security hole for browsers that support the header.
  50. ``reverse_lazy``
  51. ~~~~~~~~~~~~~~~~
  52. A lazily evaluated version of :func:`django.core.urlresolvers.reverse` was
  53. added to allow using URL reversals before the project's URLConf gets loaded.
  54. Assignment template tags
  55. ~~~~~~~~~~~~~~~~~~~~~~~~
  56. A new helper function,
  57. :ref:`assignment_tag<howto-custom-template-tags-assignment-tags>`, was added to
  58. ``template.Library`` to ease the creation of template tags that store some
  59. data in a specified context variable.
  60. .. _backwards-incompatible-changes-1.4:
  61. Backwards incompatible changes in 1.4
  62. =====================================
  63. Compatibility with old signed data
  64. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. Django 1.3 changed the cryptographic signing mechanisms used in a number of
  66. places in Django. While Django 1.3 kept fallbacks that would accept hashes
  67. produced by the previous methods, these fallbacks are removed in Django 1.4.
  68. So, if you upgrade to Django 1.4 directly from 1.2 or earlier, you may
  69. lose/invalidate certain pieces of data that have been cryptographically signed
  70. using an old method. To avoid this, use Django 1.3 first, for a period of time,
  71. to allow the signed data to expire naturally. The affected parts are detailed
  72. below, with 1) the consequences of ignoring this advice and 2) the amount of
  73. time you need to run Django 1.3 for the data to expire or become irrelevant.
  74. * contrib.sessions data integrity check
  75. * consequences: the user will be logged out, and session data will be lost.
  76. * time period: defined by SESSION_COOKIE_AGE.
  77. * contrib.auth password reset hash
  78. * consequences: password reset links from before the upgrade will not work.
  79. * time period: defined by PASSWORD_RESET_TIMEOUT_DAYS.
  80. Form related hashes — these are much shorter lifetime, and are relevant only for
  81. the short window where a user might fill in a form generated by the pre-upgrade
  82. Django instance, and try to submit it to the upgraded Django instance:
  83. * contrib.comments form security hash
  84. * consequences: the user will see a validation error "Security hash failed".
  85. * time period: the amount of time you expect users to take filling out comment
  86. forms.
  87. * FormWizard security hash
  88. * consequences: the user will see an error about the form having expired,
  89. and will be sent back to the first page of the wizard, losing the data
  90. they have inputted so far.
  91. * time period: the amount of time you expect users to take filling out the
  92. affected forms.
  93. * CSRF check
  94. * Note: This is actually a Django 1.1 fallback, not Django 1.2,
  95. and applies only if you are upgrading from 1.1.
  96. * consequences: the user will see a 403 error with any CSRF protected POST
  97. form.
  98. * time period: the amount of time you expect user to take filling out
  99. such forms.
  100. django.contrib.flatpages
  101. ~~~~~~~~~~~~~~~~~~~~~~~~
  102. Starting in the 1.4 release the
  103. :class:`~django.contrib.flatpages.middleware.FlatpageFallbackMiddleware` only
  104. adds a trailing slash and redirects if the resulting URL refers to an existing
  105. flatpage. For example, requesting ``/notaflatpageoravalidurl`` in a previous
  106. version would redirect to ``/notaflatpageoravalidurl/``, which would
  107. subsequently raise a 404. Requesting ``/notaflatpageoravalidurl`` now will
  108. immediately raise a 404. Additionally redirects returned by flatpages are now
  109. permanent (301 status code) to match the behavior of the
  110. :class:`~django.middleware.common.CommonMiddleware`.
  111. `COMMENTS_BANNED_USERS_GROUP` setting
  112. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  113. Django's :doc:`comments app </ref/contrib/comments/index>` has historically
  114. supported excluding the comments of a special user group, but we've never
  115. documented the feature properly and didn't enforce the exclusion in other parts
  116. of the app, e.g., the template tags. To fix this problem, we removed the code
  117. from the feed class.
  118. If you rely on the feature and want to restore the old behavior, simply use
  119. a custom comment model manager to exclude the user group, like this::
  120. from django.conf import settings
  121. from django.contrib.comments.managers import CommentManager
  122. class BanningCommentManager(CommentManager):
  123. def get_query_set(self):
  124. qs = super(BanningCommentManager, self).get_query_set()
  125. if getattr(settings, 'COMMENTS_BANNED_USERS_GROUP', None):
  126. where = ['user_id NOT IN (SELECT user_id FROM auth_user_groups WHERE group_id = %s)']
  127. params = [settings.COMMENTS_BANNED_USERS_GROUP]
  128. qs = qs.extra(where=where, params=params)
  129. return qs
  130. Save this model manager in your custom comment app (e.g. in
  131. ``my_comments_app/managers.py``) and add it your
  132. :ref:`custom comment app model <custom-comment-app-api>`::
  133. from django.db import models
  134. from django.contrib.comments.models import Comment
  135. from my_comments_app.managers import BanningCommentManager
  136. class CommentWithTitle(Comment):
  137. title = models.CharField(max_length=300)
  138. objects = BanningCommentManager()
  139. For more details, see the documentation about
  140. :doc:`customizing the comments framework </ref/contrib/comments/custom>`.
  141. `IGNORABLE_404_STARTS` and `IGNORABLE_404_ENDS` settings
  142. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  143. Django can report 404 errors: see :doc:`/howto/error-reporting`.
  144. Until Django 1.3, it was possible to exclude some URLs from the reporting
  145. by adding prefixes to :setting:`IGNORABLE_404_STARTS` and suffixes to
  146. :setting:`IGNORABLE_404_ENDS`.
  147. In Django 1.4, these two settings are superseded by
  148. :setting:`IGNORABLE_404_URLS`, which is a list of compiled regular expressions.
  149. Django won't send an email for 404 errors on URLs that match any of them.
  150. Furthermore, the previous settings had some rather arbitrary default values::
  151. IGNORABLE_404_STARTS = ('/cgi-bin/', '/_vti_bin', '/_vti_inf')
  152. IGNORABLE_404_ENDS = ('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi',
  153. 'favicon.ico', '.php')
  154. It's not Django's role to decide if your website has a legacy ``/cgi-bin/``
  155. section or a ``favicon.ico``. As a consequence, the default values of
  156. :setting:`IGNORABLE_404_URLS`, :setting:`IGNORABLE_404_STARTS` and
  157. :setting:`IGNORABLE_404_ENDS` are all now empty.
  158. If you have customized :setting:`IGNORABLE_404_STARTS` or
  159. :setting:`IGNORABLE_404_ENDS`, or if you want to keep the old default value,
  160. you should add the following lines in your settings file::
  161. import re
  162. IGNORABLE_404_URLS = (
  163. # for each <prefix> in IGNORABLE_404_STARTS
  164. re.compile(r'^<prefix>'),
  165. # for each <suffix> in IGNORABLE_404_ENDS
  166. re.compile(r'<suffix>$'),
  167. )
  168. Don't forget to escape characters that have a special meaning in a regular
  169. expression.
  170. CSRF protection extended to PUT and DELETE
  171. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  172. Previously, Django's :doc:`CSRF protection </ref/contrib/csrf/>` provided
  173. protection against only POST requests. Since use of PUT and DELETE methods in
  174. AJAX applications is becoming more common, we now protect all methods not
  175. defined as safe by RFC 2616 i.e. we exempt GET, HEAD, OPTIONS and TRACE, and
  176. enforce protection on everything.
  177. If you using PUT or DELETE methods in AJAX applications, please see the
  178. :ref:`instructions about using AJAX and CSRF <csrf-ajax>`.