1.2.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. Stateful template tags
  60. ----------------------
  61. Template tags that store rendering state on the node itself may experience
  62. problems if they are used with the new :ref:`cached
  63. template loader<template-loaders>`.
  64. All of the built-in Django template tags are safe to use with the cached
  65. loader, but if you're using custom template tags that come from third
  66. party packages, or that you wrote yourself, you should ensure that the
  67. ``Node`` implementation for each tag is thread-safe. For more
  68. information, see
  69. :ref:`template tag thread safety considerations<template_tag_thread_safety>`.
  70. .. _deprecated-features-1.2:
  71. Features deprecated in 1.2
  72. ==========================
  73. CSRF response rewriting middleware
  74. ----------------------------------
  75. ``CsrfResponseMiddleware``, the middleware that automatically inserted CSRF
  76. tokens into POST forms in outgoing pages, has been deprecated in favor of a
  77. template tag method (see above), and will be removed completely in Django
  78. 1.4. ``CsrfMiddleware``, which includes the functionality of
  79. ``CsrfResponseMiddleware`` and ``CsrfViewMiddleware`` has likewise been
  80. deprecated.
  81. Also, the CSRF module has moved from contrib to core, and the old imports are
  82. deprecated, as described in the :ref:`upgrading notes <ref-csrf-upgrading-notes>`.
  83. ``SMTPConnection``
  84. ------------------
  85. The ``SMTPConnection`` class has been deprecated in favor of a generic
  86. E-mail backend API. Old code that explicitly instantiated an instance
  87. of an SMTPConnection::
  88. from django.core.mail import SMTPConnection
  89. connection = SMTPConnection()
  90. messages = get_notification_email()
  91. connection.send_messages(messages)
  92. should now call :meth:`~django.core.mail.get_connection()` to
  93. instantiate a generic e-mail connection::
  94. from django.core.mail import get_connection
  95. connection = get_connection()
  96. messages = get_notification_email()
  97. connection.send_messages(messages)
  98. Depending on the value of the :setting:`EMAIL_BACKEND` setting, this
  99. may not return an SMTP connection. If you explicitly require an SMTP
  100. connection with which to send e-mail, you can explicitly request an
  101. SMTP connection::
  102. from django.core.mail import get_connection
  103. connection = get_connection('django.core.mail.backends.smtp')
  104. messages = get_notification_email()
  105. connection.send_messages(messages)
  106. If your call to construct an instance of ``SMTPConnection`` required
  107. additional arguments, those arguments can be passed to the
  108. :meth:`~django.core.mail.get_connection()` call::
  109. connection = get_connection('django.core.mail.backends.smtp', hostname='localhost', port=1234)
  110. User Messages API
  111. -----------------
  112. The API for storing messages in the user ``Message`` model (via
  113. ``user.message_set.create``) is now deprecated and will be removed in Django
  114. 1.4 according to the standard :ref:`release process <internals-release-process>`.
  115. To upgrade your code, you need to replace any instances of::
  116. user.message_set.create('a message')
  117. with the following::
  118. from django.contrib import messages
  119. messages.add_message(request, messages.INFO, 'a message')
  120. Additionally, if you make use of the method, you need to replace the
  121. following::
  122. for message in user.get_and_delete_messages():
  123. ...
  124. with::
  125. from django.contrib import messages
  126. for message in messages.get_messages(request):
  127. ...
  128. For more information, see the full
  129. :ref:`messages documentation <ref-contrib-messages>`. You should begin to
  130. update your code to use the new API immediately.
  131. What's new in Django 1.2
  132. ========================
  133. CSRF support
  134. ------------
  135. Django now has much improved protection against :ref:`Cross-Site
  136. Request Forgery (CSRF) attacks<ref-contrib-csrf>`. This type of attack
  137. occurs when a malicious Web site contains a link, a form button or
  138. some javascript that is intended to perform some action on your Web
  139. site, using the credentials of a logged-in user who visits the
  140. malicious site in their browser. A related type of attack, 'login
  141. CSRF', where an attacking site tricks a user's browser into logging
  142. into a site with someone else's credentials, is also covered.
  143. E-mail Backends
  144. ---------------
  145. You can now :ref:`configure the way that Django sends e-mail
  146. <topic-email-backends>`. Instead of using SMTP to send all e-mail, you
  147. can now choose a configurable e-mail backend to send messages. If your
  148. hosting provider uses a sandbox or some other non-SMTP technique for
  149. sending mail, you can now construct an e-mail backend that will allow
  150. Django's standard :ref:`mail sending methods<topics-email>` to use
  151. those facilities.
  152. This also makes it easier to debug mail sending - Django ships with
  153. backend implementations that allow you to send e-mail to a
  154. :ref:`file<topic-email-file-backend>`, to the
  155. :ref:`console<topic-email-console-backend>`, or to
  156. :ref:`memory<topic-email-memory-backend>` - you can even configure all
  157. e-mail to be :ref:`thrown away<topic-email-dummy-backend>`.
  158. Messages Framework
  159. ------------------
  160. Django now includes a robust and configurable :ref:`messages framework
  161. <ref-contrib-messages>` with built-in support for cookie- and session-based
  162. messaging, for both anonymous and authenticated clients. The messages framework
  163. replaces the deprecated user message API and allows you to temporarily store
  164. messages in one request and retrieve them for display in a subsequent request
  165. (usually the next one).
  166. 'Smart' if tag
  167. --------------
  168. The :ttag:`if` tag has been upgraded to be much more powerful. First, support
  169. for comparison operators has been added. No longer will you have to type:
  170. .. code-block:: html+django
  171. {% ifnotequal a b %}
  172. ...
  173. {% endifnotequal %}
  174. ...as you can now do:
  175. .. code-block:: html+django
  176. {% if a != b %}
  177. ...
  178. {% endif %}
  179. The operators supported are ``==``, ``!=``, ``<``, ``>``, ``<=``, ``>=`` and
  180. ``in``, all of which work like the Python operators, in addition to ``and``,
  181. ``or`` and ``not`` which were already supported.
  182. Also, filters may now be used in the ``if`` expression. For example:
  183. .. code-block:: html+django
  184. <div
  185. {% if user.email|lower == message.recipient|lower %}
  186. class="highlight"
  187. {% endif %}
  188. >{{ message }}</div>
  189. Template caching
  190. ----------------
  191. In previous versions of Django, every time you rendered a template it
  192. would be reloaded from disk. In Django 1.2, you can use a :ref:`cached
  193. template loader <template-loaders>` to load templates once, then use a
  194. cached the result for every subsequent render. This can lead to a
  195. significant performance improvement if your templates are broken into
  196. lots of smaller subtemplates (using the ``{% extends %}`` or ``{%
  197. include %}`` tags).
  198. As a side effect, it is now much easier to support non-Django template
  199. languages. For more details, see the :ref:`notes on supporting
  200. non-Django template languages<topic-template-alternate-language>`.
  201. Natural keys in fixtures
  202. ------------------------
  203. Fixtures can refer to remote objects using
  204. :ref:`topics-serialization-natural-keys`. This lookup scheme is an
  205. alternative to the normal primary-key based object references in a
  206. fixture, improving readability, and resolving problems referring to
  207. objects whose primary key value may not be predictable or known.