1.3.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. ============================================
  2. Django 1.3 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. This page documents release notes for the as-yet-unreleased Django
  5. 1.3. 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.3 includes a number of nifty `new features`_, lots of bug
  8. fixes, some minor `backwards incompatible changes`_ and an easy
  9. upgrade path from Django 1.2.
  10. .. _new features: `What's new in Django 1.3`_
  11. .. _backwards incompatible changes: backwards-incompatible-changes-1.3_
  12. What's new in Django 1.3
  13. ========================
  14. Class-based views
  15. ~~~~~~~~~~~~~~~~~
  16. Django 1.3 adds a framework that allows you to use a class as a view.
  17. This means you can compose a view out of a collection of methods that
  18. can be subclassed and overridden to provide common views of data without
  19. having to write too much code.
  20. Analogs of all the old function-based generic views have been
  21. provided, along with a completely generic view base class that can be
  22. used as the basis for reusable applications that can be easily
  23. extended.
  24. See :doc:`the documentation on Class-based Generic Views</topics/class-based-views>`
  25. for more details. There is also a document to help you :doc:`convert
  26. your function-based generic views to class-based
  27. views</topics/generic-views-migration>`.
  28. Logging
  29. ~~~~~~~
  30. Django 1.3 adds framework-level support for Python's logging module.
  31. This means you can now easily configure and control logging as part of
  32. your Django project. A number of logging handlers and logging calls
  33. have been added to Django's own code as well -- most notably, the
  34. error emails sent on a HTTP 500 server error are now handled as a
  35. logging activity. See :doc:`the documentation on Django's logging
  36. interface </topics/logging>` for more details.
  37. Extended static files handling
  38. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. Django 1.3 ships with a new contrib app ``'django.contrib.staticfiles'``
  40. to help developers handle the static media files (images, CSS, Javascript,
  41. etc.) that are needed to render a complete web page.
  42. In previous versions of Django, it was common to place static assets in
  43. :setting:`MEDIA_ROOT` along with user-uploaded files, and serve them both at
  44. :setting:`MEDIA_URL`. Part of the purpose of introducing the ``staticfiles``
  45. app is to make it easier to keep static files separate from user-uploaded
  46. files. For this reason, you will probably want to make your
  47. :setting:`MEDIA_ROOT` and :setting:`MEDIA_URL` different from your
  48. :setting:`STATIC_ROOT` and :setting:`STATIC_URL`. You will need to
  49. arrange for serving of files in :setting:`MEDIA_ROOT` yourself;
  50. ``staticfiles`` does not deal with user-uploaded media at all.
  51. See the :doc:`reference documentation of the app </ref/contrib/staticfiles>`
  52. for more details or learn how to :doc:`manage static files
  53. </howto/static-files>`.
  54. ``unittest2`` support
  55. ~~~~~~~~~~~~~~~~~~~~~
  56. Python 2.7 introduced some major changes to the unittest library,
  57. adding some extremely useful features. To ensure that every Django
  58. project can benefit from these new features, Django ships with a
  59. copy of unittest2_, a copy of the Python 2.7 unittest library,
  60. backported for Python 2.4 compatibility.
  61. To access this library, Django provides the
  62. ``django.utils.unittest`` module alias. If you are using Python
  63. 2.7, or you have installed unittest2 locally, Django will map the
  64. alias to the installed version of the unittest library. Otherwise,
  65. Django will use it's own bundled version of unittest2.
  66. To use this alias, simply use::
  67. from django.utils import unittest
  68. wherever you would have historically used::
  69. import unittest
  70. If you want to continue to use the base unittest libary, you can --
  71. you just won't get any of the nice new unittest2 features.
  72. .. _unittest2: http://pypi.python.org/pypi/unittest2
  73. Transaction context managers
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. Users of Python 2.5 and above may now use :ref:`transaction management functions
  76. <transaction-management-functions>` as `context managers`_. For example::
  77. with transaction.autocommit():
  78. # ...
  79. .. _context managers: http://docs.python.org/glossary.html#term-context-manager
  80. For more information, see :ref:`transaction-management-functions`.
  81. Configurable delete-cascade
  82. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83. :class:`~django.db.models.ForeignKey` and
  84. :class:`~django.db.models.OneToOneField` now accept an
  85. :attr:`~django.db.models.ForeignKey.on_delete` argument to customize behavior
  86. when the referenced object is deleted. Previously, deletes were always
  87. cascaded; available alternatives now include set null, set default, set to any
  88. value, protect, or do nothing.
  89. For more information, see the :attr:`~django.db.models.ForeignKey.on_delete`
  90. documentation.
  91. Contextual markers and comments for translatable strings
  92. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93. For translation strings with ambiguous meaning, you can now
  94. use the ``pgettext`` function to specify the context of the string.
  95. And if you just want to add some information for translators, you
  96. can also add special translator comments in the source.
  97. For more information, see :ref:`contextual-markers` and
  98. :ref:`translator-comments`.
  99. TemplateResponse
  100. ~~~~~~~~~~~~~~~~
  101. It can sometimes be beneficial to allow decorators or middleware to
  102. modify a response *after* it has been constructed by the view. For
  103. example, you may want to change the template that is used, or put
  104. additional data into the context.
  105. However, you can't (easily) modify the content of a basic
  106. :class:`~django.http.HttpResponse` after it has been constructed. To
  107. overcome this limitation, Django 1.3 adds a new
  108. :class:`~django.template.TemplateResponse` class. Unlike basic
  109. :class:`~django.http.HttpResponse` objects,
  110. :class:`~django.template.TemplateResponse` objects retain the details
  111. of the template and context that was provided by the view to compute
  112. the response. The final output of the response is not computed until
  113. it is needed, later in the response process.
  114. For more details, see the :ref:`documentation </ref/template-response>`
  115. on the :class:`~django.template.TemplateResponse` class.
  116. Everything else
  117. ~~~~~~~~~~~~~~~
  118. Django :doc:`1.1 <1.1>` and :doc:`1.2 <1.2>` added
  119. lots of big ticket items to Django, like multiple-database support,
  120. model validation, and a session-based messages framework. However,
  121. this focus on big features came at the cost of lots of smaller
  122. features.
  123. To compensate for this, the focus of the Django 1.3 development
  124. process has been on adding lots of smaller, long standing feature
  125. requests. These include:
  126. * Improved tools for accessing and manipulating the current Site.
  127. * A :class:`~django.test.client.RequestFactory` for mocking
  128. requests in tests.
  129. * A new test assertion --
  130. :meth:`~django.test.client.Client.assertNumQueries` -- making it
  131. easier to test the database activity associated with a view.
  132. * :ref:`Versioning <cache_versioning>`, :ref:`site-wide prefixing
  133. <cache_key_prefixing>` and :ref:`transformation
  134. <cache_key_transformation>` has been added to the cache API.
  135. * Support for lookups spanning relations in admin's ``list_filter``.
  136. * Support for _HTTPOnly cookies.
  137. * mail_admins() and mail_managers() now support easily attaching
  138. HTML content to messages.
  139. * Error emails now include more of the detail and formatting of
  140. the debug server error page.
  141. .. _HTTPOnly: http://www.owasp.org/index.php/HTTPOnly
  142. .. _backwards-incompatible-changes-1.3:
  143. Backwards-incompatible changes in 1.3
  144. =====================================
  145. PasswordInput default rendering behavior
  146. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147. The :class:`~django.forms.PasswordInput` form widget, intended for use
  148. with form fields which represent passwords, accepts a boolean keyword
  149. argument ``render_value`` indicating whether to send its data back to
  150. the browser when displaying a submitted form with errors. Prior to
  151. Django 1.3, this argument defaulted to ``True``, meaning that the
  152. submitted password would be sent back to the browser as part of the
  153. form. Developers who wished to add a bit of additional security by
  154. excluding that value from the redisplayed form could instantiate a
  155. :class:`~django.forms.PasswordInput` passing ``render_value=False`` .
  156. Due to the sensitive nature of passwords, however, Django 1.3 takes
  157. this step automatically; the default value of ``render_value`` is now
  158. ``False``, and developers who want the password value returned to the
  159. browser on a submission with errors (the previous behavior) must now
  160. explicitly indicate this. For example::
  161. class LoginForm(forms.Form):
  162. username = forms.CharField(max_length=100)
  163. password = forms.CharField(widget=forms.PasswordInput(render_value=True))
  164. Clearable default widget for FileField
  165. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  166. Django 1.3 now includes a ``ClearableFileInput`` form widget in addition to
  167. ``FileInput``. ``ClearableFileInput`` renders with a checkbox to clear the
  168. field's value (if the field has a value and is not required); ``FileInput``
  169. provided no means for clearing an existing file from a ``FileField``.
  170. ``ClearableFileInput`` is now the default widget for a ``FileField``, so
  171. existing forms including ``FileField`` without assigning a custom widget will
  172. need to account for the possible extra checkbox in the rendered form output.
  173. To return to the previous rendering (without the ability to clear the
  174. ``FileField``), use the ``FileInput`` widget in place of
  175. ``ClearableFileInput``. For instance, in a ``ModelForm`` for a hypothetical
  176. ``Document`` model with a ``FileField`` named ``document``::
  177. from django import forms
  178. from myapp.models import Document
  179. class DocumentForm(forms.ModelForm):
  180. class Meta:
  181. model = Document
  182. widgets = {'document': forms.FileInput}
  183. New index on database session table
  184. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  185. Prior to Django 1.3, the database table used by the database backend
  186. for the :doc:`sessions </topics/http/sessions>` app had no index on
  187. the ``expire_date`` column. As a result, date-based queries on the
  188. session table -- such as the query that is needed to purge old
  189. sessions -- would be very slow if there were lots of sessions.
  190. If you have an existing project that is using the database session
  191. backend, you don't have to do anything to accommodate this change.
  192. However, you may get a significant performance boost if you manually
  193. add the new index to the session table. The SQL that will add the
  194. index can be found by running the :djadmin:`sqlindexes` admin
  195. command::
  196. python manage.py sqlindexes sessions
  197. No more naughty words
  198. ~~~~~~~~~~~~~~~~~~~~~
  199. Django has historically provided (and enforced) a list of profanities.
  200. The :doc:`comments app </ref/contrib/comments/index>` has enforced this
  201. list of profanities, preventing people from submitting comments that
  202. contained one of those profanities.
  203. Unfortunately, the technique used to implement this profanities list
  204. was woefully naive, and prone to the `Scunthorpe problem`_. Fixing the
  205. built in filter to fix this problem would require significant effort,
  206. and since natural language processing isn't the normal domain of a web
  207. framework, we have "fixed" the problem by making the list of
  208. prohibited words an empty list.
  209. If you want to restore the old behavior, simply put a
  210. ``PROFANITIES_LIST`` setting in your settings file that includes the
  211. words that you want to prohibit (see the `commit that implemented this
  212. change`_ if you want to see the list of words that was historically
  213. prohibited). However, if avoiding profanities is important to you, you
  214. would be well advised to seek out a better, less naive approach to the
  215. problem.
  216. .. _Scunthorpe problem: http://en.wikipedia.org/wiki/Scunthorpe_problem
  217. .. _commit that implemented this change: http://code.djangoproject.com/changeset/13996
  218. Localflavor changes
  219. ~~~~~~~~~~~~~~~~~~~
  220. Django 1.3 introduces the following backwards-incompatible changes to
  221. local flavors:
  222. * Indonesia (id) -- The province "Nanggroe Aceh Darussalam (NAD)"
  223. has been removed from the province list in favor of the new
  224. official designation "Aceh (ACE)".
  225. FormSet updates
  226. ~~~~~~~~~~~~~~~
  227. In Django 1.3 ``FormSet`` creation behavior is modified slightly. Historically
  228. the class didn't make a distinction between not being passed data and being
  229. passed empty dictionary. This was inconsistent with behavior in other parts of
  230. the framework. Starting with 1.3 if you pass in empty dictionary the
  231. ``FormSet`` will raise a ``ValidationError``.
  232. For example with a ``FormSet``::
  233. >>> class ArticleForm(Form):
  234. ... title = CharField()
  235. ... pub_date = DateField()
  236. >>> ArticleFormSet = formset_factory(ArticleForm)
  237. the following code will raise a ``ValidationError``::
  238. >>> ArticleFormSet({})
  239. Traceback (most recent call last):
  240. ...
  241. ValidationError: [u'ManagementForm data is missing or has been tampered with']
  242. if you need to instantiate an empty ``FormSet``, don't pass in the data or use
  243. ``None``::
  244. >>> formset = ArticleFormSet()
  245. >>> formset = ArticleFormSet(data=None)
  246. .. _deprecated-features-1.3:
  247. Features deprecated in 1.3
  248. ==========================
  249. Django 1.3 deprecates some features from earlier releases.
  250. These features are still supported, but will be gradually phased out
  251. over the next few release cycles.
  252. Code taking advantage of any of the features below will raise a
  253. ``PendingDeprecationWarning`` in Django 1.3. This warning will be
  254. silent by default, but may be turned on using Python's `warnings
  255. module`_, or by running Python with a ``-Wd`` or `-Wall` flag.
  256. .. _warnings module: http://docs.python.org/library/warnings.html
  257. In Django 1.4, these warnings will become a ``DeprecationWarning``,
  258. which is *not* silent. In Django 1.5 support for these features will
  259. be removed entirely.
  260. .. seealso::
  261. For more details, see the documentation :doc:`Django's release process
  262. </internals/release-process>` and our :doc:`deprecation timeline
  263. </internals/deprecation>`.
  264. ``mod_python`` support
  265. ~~~~~~~~~~~~~~~~~~~~~~
  266. The ``mod_python`` library has not had a release since 2007 or a commit since
  267. 2008. The Apache Foundation board voted to remove ``mod_python`` from the set
  268. of active projects in its version control repositories, and its lead developer
  269. has shifted all of his efforts toward the lighter, slimmer, more stable, and
  270. more flexible ``mod_wsgi`` backend.
  271. If you are currently using the ``mod_python`` request handler, you
  272. should redeploy your Django projects using another request handler.
  273. :doc:`mod_wsgi </howto/deployment/modwsgi>` is the request handler
  274. recommended by the Django project, but :doc:`FastCGI
  275. </howto/deployment/fastcgi>` is also supported. Support for
  276. ``mod_python`` deployment will be removed in Django 1.5.
  277. Function-based generic views
  278. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  279. As a result of the introduction of class-based generic views, the
  280. function-based generic views provided by Django have been deprecated.
  281. The following modules and the views they contain have been deprecated:
  282. * :mod:`django.views.generic.create_update`
  283. * :mod:`django.views.generic.date_based`
  284. * :mod:`django.views.generic.list_detail`
  285. * :mod:`django.views.generic.simple`
  286. Test client response ``template`` attribute
  287. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  288. Django's :ref:`test client <test-client>` returns
  289. :class:`~django.test.client.Response` objects annotated with extra testing
  290. information. In Django versions prior to 1.3, this included a
  291. :attr:`~django.test.client.Response.template` attribute containing information
  292. about templates rendered in generating the response: either None, a single
  293. :class:`~django.template.Template` object, or a list of
  294. :class:`~django.template.Template` objects. This inconsistency in return values
  295. (sometimes a list, sometimes not) made the attribute difficult to work with.
  296. In Django 1.3 the :attr:`~django.test.client.Response.template` attribute is
  297. deprecated in favor of a new :attr:`~django.test.client.Response.templates`
  298. attribute, which is always a list, even if it has only a single element or no
  299. elements.
  300. ``DjangoTestRunner``
  301. ~~~~~~~~~~~~~~~~~~~~
  302. As a result of the introduction of support for unittest2, the features
  303. of :class:`django.test.simple.DjangoTestRunner` (including fail-fast
  304. and Ctrl-C test termination) have been made redundant. In view of this
  305. redundancy, :class:`~django.test.simple.DjangoTestRunner` has been
  306. turned into an empty placeholder class, and will be removed entirely
  307. in Django 1.5.
  308. Changes to :ttag:`url` and :ttag:`ssi`
  309. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  310. Most template tags will allow you to pass in either constants or
  311. variables as arguments -- for example::
  312. {% extends "base.html" %}
  313. allows you to specify a base template as a constant, but if you have a
  314. context variable ``templ`` that contains the value ``base.html``::
  315. {% extends templ %}
  316. is also legal.
  317. However, due to an accident of history, the :ttag:`url` and
  318. :ttag:`ssi` are different. These tags use the second, quoteless
  319. syntax, but interpret the argument as a constant. This means it isn't
  320. possible to use a context variable as the target of a :ttag:`url` and
  321. :ttag:`ssi` tag.
  322. Django 1.3 marks the start of the process to correct this historical
  323. accident. Django 1.3 adds a new template library -- ``future`` -- that
  324. provides alternate implementations of the :ttag:`url` and :ttag:`ssi`
  325. template tags. This ``future`` library implement behavior that makes
  326. the handling of the first argument consistent with the handling of all
  327. other variables. So, an existing template that contains::
  328. {% url sample %}
  329. should be replaced with::
  330. {% load url from future %}
  331. {% url 'sample' %}
  332. The tags implementing the old behavior have been deprecated, and in
  333. Django 1.5, the old behavior will be replaced with the new behavior.
  334. To ensure compatibility with future versions of Django, existing
  335. templates should be modified to use the new ``future`` libraries and
  336. syntax.
  337. Changes to the login methods of the admin
  338. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  339. In previous version the admin app defined login methods in multiple locations
  340. and ignored the almost identical implementation in the already used auth app.
  341. A side effect of this duplication was the missing adoption of the changes made
  342. in r12634_ to support a broader set of characters for usernames.
  343. This release refactores the admin's login mechanism to use a subclass of the
  344. :class:`~django.contrib.auth.forms.AuthenticationForm` instead of a manual
  345. form validation. The previously undocumented method
  346. ``'django.contrib.admin.sites.AdminSite.display_login_form'`` has been removed
  347. in favor of a new :attr:`~django.contrib.admin.AdminSite.login_form`
  348. attribute.
  349. .. _r12634: http://code.djangoproject.com/changeset/12634