1.2.txt 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. .. _releases-1.2:
  2. ============================================
  3. Django 1.2 release notes — UNDER DEVELOPMENT
  4. ============================================
  5. This page documents release notes for the as-yet-unreleased Django 1.2. As such
  6. it is tentative and subject to change. It provides up-to-date information for
  7. those who are following trunk.
  8. Django 1.2 includes a number of nifty `new features`_, lots of bug
  9. fixes, and an easy upgrade path from Django 1.1.
  10. .. _new features: `What's new in Django 1.2`_
  11. .. _backwards-incompatible-changes-1.2:
  12. Backwards-incompatible changes in 1.2
  13. =====================================
  14. CSRF Protection
  15. ---------------
  16. There have been large changes to the way that CSRF protection works, detailed in
  17. :ref:`the CSRF documentaton <ref-contrib-csrf>`. The following are the major
  18. changes that developers must be aware of:
  19. * ``CsrfResponseMiddleware`` and ``CsrfMiddleware`` have been deprecated, and
  20. will be removed completely in Django 1.4, in favor of a template tag that
  21. should be inserted into forms.
  22. * All contrib apps use a ``csrf_protect`` decorator to protect the view. This
  23. requires the use of the csrf_token template tag in the template, so if you
  24. have used custom templates for contrib views, you MUST READ THE :ref:`UPGRADE
  25. INSTRUCTIONS <ref-csrf-upgrading-notes>` to fix those templates.
  26. * ``CsrfViewMiddleware`` is included in :setting:`MIDDLEWARE_CLASSES` by
  27. default. This turns on CSRF protection by default, so that views that accept
  28. POST requests need to be written to work with the middleware. Instructions
  29. on how to do this are found in the CSRF docs.
  30. * All of the CSRF has moved from contrib to core (with backwards compatible
  31. imports in the old locations, which are deprecated).
  32. :ttag:`if` tag changes
  33. ----------------------
  34. Due to new features in the :ttag:`if` template tag, it no longer accepts 'and',
  35. 'or' and 'not' as valid **variable** names. Previously that worked in some
  36. cases even though these strings were normally treated as keywords. Now, the
  37. keyword status is always enforced, and template code like ``{% if not %}`` or
  38. ``{% if and %}`` will throw a TemplateSyntaxError.
  39. ``LazyObject``
  40. --------------
  41. ``LazyObject`` is an undocumented utility class used for lazily wrapping other
  42. objects of unknown type. In Django 1.1 and earlier, it handled introspection in
  43. a non-standard way, depending on wrapped objects implementing a public method
  44. ``get_all_members()``. Since this could easily lead to name clashes, it has been
  45. changed to use the standard method, involving ``__members__`` and ``__dir__()``.
  46. If you used ``LazyObject`` in your own code, and implemented the
  47. ``get_all_members()`` method for wrapped objects, you need to make the following
  48. changes:
  49. * If your class does not have special requirements for introspection (i.e. you
  50. have not implemented ``__getattr__()`` or other methods that allow for
  51. attributes not discoverable by normal mechanisms), you can simply remove the
  52. ``get_all_members()`` method. The default implementation on ``LazyObject``
  53. will do the right thing.
  54. * If you have more complex requirements for introspection, first rename the
  55. ``get_all_members()`` method to ``__dir__()``. This is the standard method,
  56. from Python 2.6 onwards, for supporting introspection. If you are require
  57. support for Python < 2.6, add the following code to the class::
  58. __members__ = property(lambda self: self.__dir__())
  59. .. _deprecated-features-1.2:
  60. Features deprecated in 1.2
  61. ==========================
  62. CSRF response rewriting middleware
  63. ----------------------------------
  64. ``CsrfResponseMiddleware``, the middleware that automatically inserted CSRF
  65. tokens into POST forms in outgoing pages, has been deprecated in favor of a
  66. template tag method (see above), and will be removed completely in Django
  67. 1.4. ``CsrfMiddleware``, which includes the functionality of
  68. ``CsrfResponseMiddleware`` and ``CsrfViewMiddleware`` has likewise been
  69. deprecated.
  70. Also, the CSRF module has moved from contrib to core, and the old imports are
  71. deprecated, as described in the :ref:`upgrading notes <ref-csrf-upgrading-notes>`.
  72. ``SMTPConnection``
  73. ------------------
  74. The ``SMTPConnection`` class has been deprecated in favor of a generic
  75. E-mail backend API. Old code that explicitly instantiated an instance
  76. of an SMTPConnection::
  77. from django.core.mail import SMTPConnection
  78. connection = SMTPConnection()
  79. messages = get_notification_email()
  80. connection.send_messages(messages)
  81. should now call :meth:`~django.core.mail.get_connection()` to
  82. instantiate a generic e-mail connection::
  83. from django.core.mail import get_connection
  84. connection = get_connection()
  85. messages = get_notification_email()
  86. connection.send_messages(messages)
  87. Depending on the value of the :setting:`EMAIL_BACKEND` setting, this
  88. may not return an SMTP connection. If you explicitly require an SMTP
  89. connection with which to send e-mail, you can explicitly request an
  90. SMTP connection::
  91. from django.core.mail import get_connection
  92. connection = get_connection('django.core.mail.backends.smtp')
  93. messages = get_notification_email()
  94. connection.send_messages(messages)
  95. If your call to construct an instance of ``SMTPConnection`` required
  96. additional arguments, those arguments can be passed to the
  97. :meth:`~django.core.mail.get_connection()` call::
  98. connection = get_connection('django.core.mail.backends.smtp', hostname='localhost', port=1234)
  99. User Messages API
  100. -----------------
  101. The API for storing messages in the user ``Message`` model (via
  102. ``user.message_set.create``) is now deprecated and will be removed in Django
  103. 1.4 according to the standard :ref:`release process <internals-release-process>`.
  104. To upgrade your code, you need to replace any instances of::
  105. user.message_set.create('a message')
  106. with the following::
  107. from django.contrib import messages
  108. messages.add_message(request, messages.INFO, 'a message')
  109. Additionally, if you make use of the method, you need to replace the
  110. following::
  111. for message in user.get_and_delete_messages():
  112. ...
  113. with::
  114. from django.contrib import messages
  115. for message in messages.get_messages(request):
  116. ...
  117. For more information, see the full
  118. :ref:`messages documentation <ref-contrib-messages>`. You should begin to
  119. update your code to use the new API immediately.
  120. What's new in Django 1.2
  121. ========================
  122. CSRF support
  123. ------------
  124. Django now has much improved protection against :ref:`Cross-Site
  125. Request Forgery (CSRF) attacks<ref-contrib-csrf>`. This type of attack
  126. occurs when a malicious Web site contains a link, a form button or
  127. some javascript that is intended to perform some action on your Web
  128. site, using the credentials of a logged-in user who visits the
  129. malicious site in their browser. A related type of attack, 'login
  130. CSRF', where an attacking site tricks a user's browser into logging
  131. into a site with someone else's credentials, is also covered.
  132. E-mail Backends
  133. ---------------
  134. You can now :ref:`configure the way that Django sends e-mail
  135. <topic-email-backends>`. Instead of using SMTP to send all e-mail, you
  136. can now choose a configurable e-mail backend to send messages. If your
  137. hosting provider uses a sandbox or some other non-SMTP technique for
  138. sending mail, you can now construct an e-mail backend that will allow
  139. Django's standard :ref:`mail sending methods<topics-email>` to use
  140. those facilities.
  141. This also makes it easier to debug mail sending - Django ships with
  142. backend implementations that allow you to send e-mail to a
  143. :ref:`file<topic-email-file-backend>`, to the
  144. :ref:`console<topic-email-console-backend>`, or to
  145. :ref:`memory<topic-email-memory-backend>` - you can even configure all
  146. e-mail to be :ref:`thrown away<topic-email-dummy-backend>`.
  147. Messages Framework
  148. ------------------
  149. Django now includes a robust and configurable :ref:`messages framework
  150. <ref-contrib-messages>` with built-in support for cookie- and session-based
  151. messaging, for both anonymous and authenticated clients. The messages framework
  152. replaces the deprecated user message API and allows you to temporarily store
  153. messages in one request and retrieve them for display in a subsequent request
  154. (usually the next one).
  155. 'Smart' if tag
  156. --------------
  157. The :ttag:`if` tag has been upgraded to be much more powerful. First, support
  158. for comparison operators has been added. No longer will you have to type:
  159. .. code-block:: html+django
  160. {% ifnotequal a b %}
  161. ...
  162. {% endifnotequal %}
  163. ...as you can now do:
  164. .. code-block:: html+django
  165. {% if a != b %}
  166. ...
  167. {% endif %}
  168. The operators supported are ``==``, ``!=``, ``<``, ``>``, ``<=``, ``>=`` and
  169. ``in``, all of which work like the Python operators, in addition to ``and``,
  170. ``or`` and ``not`` which were already supported.
  171. Also, filters may now be used in the ``if`` expression. For example:
  172. .. code-block:: html+django
  173. <div
  174. {% if user.email|lower == message.recipient|lower %}
  175. class="highlight"
  176. {% endif %}
  177. >{{ message }}</div>