1.4.txt 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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`_. We've also dropped some features, which are detailed
  9. in :doc:`our deprecation plan </internals/deprecation>`, and we've
  10. `begun the deprecation process for some features`_.
  11. .. _`new features`: `What's new in Django 1.4`_
  12. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.4`_
  13. .. _`begun the deprecation process for some features`: `Features deprecated in 1.4`_
  14. Python compatibility
  15. ====================
  16. Django 1.4 has dropped support for Python 2.4. Python 2.5 is now the minimum
  17. required Python version. Django is tested and supported on Python 2.5, 2.6 and
  18. 2.7.
  19. This change should affect only a small number of Django users, as most
  20. operating-system vendors today are shipping Python 2.5 or newer as their default
  21. version. If you're still using Python 2.4, however, you'll need to stick to
  22. Django 1.3 until you can upgrade. Per :doc:`our support policy
  23. </internals/release-process>`, Django 1.3 will continue to receive security
  24. support until the release of Django 1.5.
  25. Django does not support Python 3.x at this time. At some point before the
  26. release of Django 1.4, we plan to publish a document outlining our full
  27. timeline for deprecating Python 2.x and moving to Python 3.x.
  28. What's new in Django 1.4
  29. ========================
  30. Support for in-browser testing frameworks
  31. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. Django 1.4 supports integration with in-browser testing frameworks like
  33. Selenium_. The new :class:`django.test.LiveServerTestCase` base class lets you
  34. test the interactions between your site's front and back ends more
  35. comprehensively. See the
  36. :class:`documentation<django.test.LiveServerTestCase>` for more details and
  37. concrete examples.
  38. .. _Selenium: http://seleniumhq.org/
  39. ``SELECT FOR UPDATE`` support
  40. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41. Django 1.4 includes a :meth:`QuerySet.select_for_update()
  42. <django.db.models.query.QuerySet.select_for_update>` method, which generates a
  43. ``SELECT ... FOR UPDATE`` SQL query. This will lock rows until the end of the
  44. transaction, meaning other transactions cannot modify or delete rows matched by
  45. a ``FOR UPDATE`` query.
  46. For more details, see the documentation for
  47. :meth:`~django.db.models.query.QuerySet.select_for_update`.
  48. ``Model.objects.bulk_create`` in the ORM
  49. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. This method lets you create multiple objects more efficiently. It can result in
  51. significant performance increases if you have many objects.
  52. Django makes use of this internally, meaning some operations (such as database
  53. setup for test suites) have seen a performance benefit as a result.
  54. See the :meth:`~django.db.models.query.QuerySet.bulk_create` docs for more
  55. information.
  56. ``QuerySet.prefetch_related``
  57. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58. Similar to :meth:`~django.db.models.query.QuerySet.select_related` but with a
  59. different strategy and broader scope,
  60. :meth:`~django.db.models.query.QuerySet.prefetch_related` has been added to
  61. :class:`~django.db.models.query.QuerySet`. This method returns a new
  62. ``QuerySet`` that will prefetch each of the specified related lookups in a
  63. single batch as soon as the query begins to be evaluated. Unlike
  64. ``select_related``, it does the joins in Python, not in the database, and
  65. supports many-to-many relationships,
  66. :class:`~django.contrib.contenttypes.generic.GenericForeignKey` and more. This
  67. allows you to fix a very common performance problem in which your code ends up
  68. doing O(n) database queries (or worse) if objects on your primary ``QuerySet``
  69. each have many related objects that you also need to fetch.
  70. Improved password hashing
  71. ~~~~~~~~~~~~~~~~~~~~~~~~~
  72. Django's auth system (``django.contrib.auth``) stores passwords using a one-way
  73. algorithm. Django 1.3 uses the SHA1_ algorithm, but increasing processor speeds
  74. and theoretical attacks have revealed that SHA1 isn't as secure as we'd like.
  75. Thus, Django 1.4 introduces a new password storage system: by default Django now
  76. uses the PBKDF2_ algorithm (as recommended by NIST_). You can also easily choose
  77. a different algorithm (including the popular bcrypt_ algorithm). For more
  78. details, see :ref:`auth_password_storage`.
  79. .. _sha1: http://en.wikipedia.org/wiki/SHA1
  80. .. _pbkdf2: http://en.wikipedia.org/wiki/PBKDF2
  81. .. _nist: http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf
  82. .. _bcrypt: http://en.wikipedia.org/wiki/Bcrypt
  83. HTML5 doctype
  84. ~~~~~~~~~~~~~
  85. We've switched the admin and other bundled templates to use the HTML5
  86. doctype. While Django will be careful to maintain compatibility with older
  87. browsers, this change means that you can use any HTML5 features you need in
  88. admin pages without having to lose HTML validity or override the provided
  89. templates to change the doctype.
  90. List filters in admin interface
  91. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92. Prior to Django 1.4, the :mod:`~django.contrib.admin` app let you specify
  93. change list filters by specifying a field lookup, but it didn't allow you to
  94. create custom filters. This has been rectified with a simple API (previously
  95. used internally and known as "FilterSpec"). For more details, see the
  96. documentation for :attr:`~django.contrib.admin.ModelAdmin.list_filter`.
  97. Multiple sort in admin interface
  98. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  99. The admin change list now supports sorting on multiple columns. It respects all
  100. elements of the :attr:`~django.contrib.admin.ModelAdmin.ordering` attribute, and
  101. sorting on multiple columns by clicking on headers is designed to mimic the
  102. behavior of desktop GUIs. We also added a
  103. :meth:`~django.contrib.admin.ModelAdmin.get_ordering` method for specifying the
  104. ordering dynamically (i.e., depending on the request).
  105. New ``ModelAdmin`` methods
  106. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  107. We added a :meth:`~django.contrib.admin.ModelAdmin.save_related` method to
  108. :mod:`~django.contrib.admin.ModelAdmin` to ease customization of how
  109. related objects are saved in the admin.
  110. Two other new :class:`~django.contrib.admin.ModelAdmin` methods,
  111. :meth:`~django.contrib.admin.ModelAdmin.get_list_display` and
  112. :meth:`~django.contrib.admin.ModelAdmin.get_list_display_links`
  113. enable dynamic customization of fields and links displayed on the admin
  114. change list.
  115. Admin inlines respect user permissions
  116. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  117. Admin inlines now only allow those actions for which the user has
  118. permission. For ``ManyToMany`` relationships with an auto-created intermediate
  119. model (which does not have its own permissions), the change permission for the
  120. related model determines if the user has the permission to add, change or
  121. delete relationships.
  122. Tools for cryptographic signing
  123. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  124. Django 1.4 adds both a low-level API for signing values and a high-level API
  125. for setting and reading signed cookies, one of the most common uses of
  126. signing in Web applications.
  127. See the :doc:`cryptographic signing </topics/signing>` docs for more
  128. information.
  129. Cookie-based session backend
  130. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  131. Django 1.4 introduces a cookie-based session backend that uses the tools for
  132. :doc:`cryptographic signing </topics/signing>` to store the session data in
  133. the client's browser.
  134. .. warning::
  135. Session data is signed and validated by the server, but it's not
  136. encrypted. This means a user can view any data stored in the
  137. session but cannot change it. Please read the documentation for
  138. further clarification before using this backend.
  139. See the :ref:`cookie-based session backend <cookie-session-backend>` docs for
  140. more information.
  141. New form wizard
  142. ~~~~~~~~~~~~~~~
  143. The previous ``FormWizard`` from the formtools contrib app has been
  144. replaced with a new implementation based on the class-based views
  145. introduced in Django 1.3. It features a pluggable storage API and doesn't
  146. require the wizard to pass around hidden fields for every previous step.
  147. Django 1.4 ships with a session-based storage backend and a cookie-based
  148. storage backend. The latter uses the tools for
  149. :doc:`cryptographic signing </topics/signing>` also introduced in
  150. Django 1.4 to store the wizard's state in the user's cookies.
  151. See the :doc:`form wizard </ref/contrib/formtools/form-wizard>` docs for
  152. more information.
  153. ``reverse_lazy``
  154. ~~~~~~~~~~~~~~~~
  155. A lazily evaluated version of :func:`django.core.urlresolvers.reverse` was
  156. added to allow using URL reversals before the project's URLconf gets loaded.
  157. Translating URL patterns
  158. ~~~~~~~~~~~~~~~~~~~~~~~~
  159. Django can now look for a language prefix in the URLpattern when using the new
  160. :func:`~django.conf.urls.i18n.i18n_patterns` helper function.
  161. It's also now possible to define translatable URL patterns using
  162. :func:`~django.utils.translation.ugettext_lazy`. See
  163. :ref:`url-internationalization` for more information about the language prefix
  164. and how to internationalize URL patterns.
  165. Contextual translation support for ``{% trans %}`` and ``{% blocktrans %}``
  166. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167. The :ref:`contextual translation<contextual-markers>` support introduced in
  168. Django 1.3 via the ``pgettext`` function has been extended to the
  169. :ttag:`trans` and :ttag:`blocktrans` template tags using the new ``context``
  170. keyword.
  171. Customizable ``SingleObjectMixin`` URLConf kwargs
  172. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  173. Two new attributes,
  174. :attr:`pk_url_kwarg<django.views.generic.detail.SingleObjectMixin.pk_url_kwarg>`
  175. and
  176. :attr:`slug_url_kwarg<django.views.generic.detail.SingleObjectMixin.slug_url_kwarg>`,
  177. have been added to :class:`~django.views.generic.detail.SingleObjectMixin` to
  178. enable the customization of URLconf keyword arguments used for single
  179. object generic views.
  180. Assignment template tags
  181. ~~~~~~~~~~~~~~~~~~~~~~~~
  182. A new :ref:`assignment_tag<howto-custom-template-tags-assignment-tags>` helper
  183. function was added to ``template.Library`` to ease the creation of template
  184. tags that store data in a specified context variable.
  185. ``*args`` and ``**kwargs`` support for template tag helper functions
  186. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  187. The :ref:`simple_tag<howto-custom-template-tags-simple-tags>`,
  188. :ref:`inclusion_tag <howto-custom-template-tags-inclusion-tags>` and
  189. newly introduced
  190. :ref:`assignment_tag<howto-custom-template-tags-assignment-tags>` template
  191. helper functions may now accept any number of positional or keyword arguments.
  192. For example:
  193. .. code-block:: python
  194. @register.simple_tag
  195. def my_tag(a, b, *args, **kwargs):
  196. warning = kwargs['warning']
  197. profile = kwargs['profile']
  198. ...
  199. return ...
  200. Then, in the template, any number of arguments may be passed to the template tag.
  201. For example:
  202. .. code-block:: html+django
  203. {% my_tag 123 "abcd" book.title warning=message|lower profile=user.profile %}
  204. No wrapping of exceptions in ``TEMPLATE_DEBUG`` mode
  205. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  206. In previous versions of Django, whenever the :setting:`TEMPLATE_DEBUG` setting
  207. was ``True``, any exception raised during template rendering (even exceptions
  208. unrelated to template syntax) were wrapped in ``TemplateSyntaxError`` and
  209. re-raised. This was done in order to provide detailed template source location
  210. information in the debug 500 page.
  211. In Django 1.4, exceptions are no longer wrapped. Instead, the original
  212. exception is annotated with the source information. This means that catching
  213. exceptions from template rendering is now consistent regardless of the value of
  214. :setting:`TEMPLATE_DEBUG`, and there's no need to catch and unwrap
  215. ``TemplateSyntaxError`` in order to catch other errors.
  216. ``truncatechars`` template filter
  217. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  218. This new filter truncates a string to be no longer than the specified
  219. number of characters. Truncated strings end with a translatable ellipsis
  220. sequence ("..."). See the documentation for :tfilter:`truncatechars` for
  221. more details.
  222. ``static`` template tag
  223. ~~~~~~~~~~~~~~~~~~~~~~~
  224. The :mod:`staticfiles<django.contrib.staticfiles>` contrib app has a new
  225. :ttag:`static<staticfiles-static>` template tag to refer to files saved with
  226. the :setting:`STATICFILES_STORAGE` storage backend. It uses the storage
  227. backend's ``url`` method and therefore supports advanced features such as
  228. :ref:`serving files from a cloud service<staticfiles-from-cdn>`.
  229. ``CachedStaticFilesStorage`` storage backend
  230. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  231. The :mod:`staticfiles<django.contrib.staticfiles>` contrib app now has a
  232. :class:`~django.contrib.staticfiles.storage.CachedStaticFilesStorage` backend
  233. that caches the files it saves (when running the :djadmin:`collectstatic`
  234. management command) by appending the MD5 hash of the file's content to the
  235. filename. For example, the file ``css/styles.css`` would also be saved as
  236. ``css/styles.55e7cbb9ba48.css``
  237. See the :class:`~django.contrib.staticfiles.storage.CachedStaticFilesStorage`
  238. docs for more information.
  239. Simple clickjacking protection
  240. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  241. We've added a middleware to provide easy protection against `clickjacking
  242. <http://en.wikipedia.org/wiki/Clickjacking>`_ using the ``X-Frame-Options``
  243. header. It's not enabled by default for backwards compatibility reasons, but
  244. you'll almost certainly want to :doc:`enable it </ref/clickjacking/>` to help
  245. plug that security hole for browsers that support the header.
  246. CSRF improvements
  247. ~~~~~~~~~~~~~~~~~
  248. We've made various improvements to our CSRF features, including the
  249. :func:`~django.views.decorators.csrf.ensure_csrf_cookie` decorator, which can
  250. help with AJAX-heavy sites; protection for PUT and DELETE requests; and the
  251. :setting:`CSRF_COOKIE_SECURE` and :setting:`CSRF_COOKIE_PATH` settings, which can
  252. improve the security and usefulness of CSRF protection. See the :doc:`CSRF
  253. docs </ref/contrib/csrf>` for more information.
  254. Error report filtering
  255. ~~~~~~~~~~~~~~~~~~~~~~
  256. We added two function decorators, :func:`sensitive_variables` and
  257. :func:`sensitive_post_parameters`, to allow designating the local variables
  258. and POST parameters that may contain sensitive information and should be
  259. filtered out of error reports.
  260. All POST parameters are now systematically filtered out of error reports for
  261. certain views (``login``, ``password_reset_confirm``, ``password_change`` and
  262. ``add_view`` in :mod:`django.contrib.auth.views`, as well as
  263. ``user_change_password`` in the admin app) to prevent the leaking of sensitive
  264. information such as user passwords.
  265. You can override or customize the default filtering by writing a :ref:`custom
  266. filter<custom-error-reports>`. For more information see the docs on
  267. :ref:`Filtering error reports<filtering-error-reports>`.
  268. Extended IPv6 support
  269. ~~~~~~~~~~~~~~~~~~~~~
  270. The previously added support for IPv6 addresses when using the runserver
  271. management command in Django 1.3 has been extended with
  272. a :class:`~django.db.models.fields.GenericIPAddressField` model field,
  273. a :class:`~django.forms.fields.GenericIPAddressField` form field and
  274. the validators :data:`~django.core.validators.validate_ipv46_address` and
  275. :data:`~django.core.validators.validate_ipv6_address`
  276. Updated default project layout and ``manage.py``
  277. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  278. Django 1.4 ships with an updated default project layout and ``manage.py`` file
  279. for the :djadmin:`startproject` management command. These fix some issues with
  280. the previous ``manage.py`` handling of Python import paths that caused double
  281. imports, trouble moving from development to deployment, and other
  282. difficult-to-debug path issues.
  283. The previous ``manage.py`` called functions that are now deprecated, and thus
  284. projects upgrading to Django 1.4 should update their ``manage.py``. (The
  285. old-style ``manage.py`` will continue to work as before until Django 1.6. In
  286. 1.5 it will raise ``DeprecationWarning``).
  287. The new recommended ``manage.py`` file should look like this::
  288. #!/usr/bin/env python
  289. import os, sys
  290. if __name__ == "__main__":
  291. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings")
  292. from django.core.management import execute_from_command_line
  293. execute_from_command_line(sys.argv)
  294. ``{{ project_name }}`` should be replaced with the Python package name of the
  295. actual project.
  296. If settings, URLconfs and apps within the project are imported or referenced
  297. using the project name prefix (e.g. ``myproject.settings``, ``ROOT_URLCONF =
  298. "myproject.urls"``, etc), the new ``manage.py`` will need to be moved one
  299. directory up, so it is outside the project package rather than adjacent to
  300. ``settings.py`` and ``urls.py``.
  301. For instance, with the following layout::
  302. manage.py
  303. mysite/
  304. __init__.py
  305. settings.py
  306. urls.py
  307. myapp/
  308. __init__.py
  309. models.py
  310. You could import ``mysite.settings``, ``mysite.urls``, and ``mysite.myapp``,
  311. but not ``settings``, ``urls``, or ``myapp`` as top-level modules.
  312. Anything imported as a top-level module can be placed adjacent to the new
  313. ``manage.py``. For instance, to decouple "myapp" from the project module and
  314. import it as just ``myapp``, place it outside the ``mysite/`` directory::
  315. manage.py
  316. myapp/
  317. __init__.py
  318. models.py
  319. mysite/
  320. __init__.py
  321. settings.py
  322. urls.py
  323. If the same code is imported inconsistently (some places with the project
  324. prefix, some places without it), the imports will need to be cleaned up when
  325. switching to the new ``manage.py``.
  326. Improved WSGI support
  327. ~~~~~~~~~~~~~~~~~~~~~
  328. The :djadmin:`startproject` management command now adds a :file:`wsgi.py`
  329. module to the initial project layout, containing a simple WSGI application that
  330. can be used for :doc:`deploying with WSGI app
  331. servers</howto/deployment/wsgi/index>`.
  332. The :djadmin:`built-in development server<runserver>` now supports using an
  333. externally-defined WSGI callable, which makes it possible to run runserver
  334. with the same WSGI configuration that is used for deployment. The new
  335. :setting:`WSGI_APPLICATION` setting lets you configure which WSGI callable
  336. :djadmin:`runserver` uses.
  337. (The :djadmin:`runfcgi` management command also internally wraps the WSGI
  338. callable configured via :setting:`WSGI_APPLICATION`.)
  339. Custom project and app templates
  340. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  341. The :djadmin:`startapp` and :djadmin:`startproject` management commands
  342. now have a ``--template`` option for specifying a path or URL to a custom app
  343. or project template.
  344. For example, Django will use the ``/path/to/my_project_template`` directory
  345. when you run the following command::
  346. django-admin.py startproject --template=/path/to/my_project_template myproject
  347. You can also now provide a destination directory as the second
  348. argument to both :djadmin:`startapp` and :djadmin:`startproject`::
  349. django-admin.py startapp myapp /path/to/new/app
  350. django-admin.py startproject myproject /path/to/new/project
  351. For more information, see the :djadmin:`startapp` and :djadmin:`startproject`
  352. documentation.
  353. Support for time zones
  354. ~~~~~~~~~~~~~~~~~~~~~~
  355. Django 1.4 adds :ref:`support for time zones <time-zones>`. When it's enabled,
  356. Django stores date and time information in UTC in the database, uses
  357. time-zone-aware datetime objects internally and translates them to the end user's
  358. time zone in templates and forms.
  359. Reasons for using this feature include:
  360. - Customizing date and time display for users around the world.
  361. - Storing datetimes in UTC for database portability and interoperability.
  362. (This argument doesn't apply to PostgreSQL, because it already stores
  363. timestamps with time zone information in Django 1.3.)
  364. - Avoiding data corruption problems around DST transitions.
  365. Time zone support is enabled by default in new projects created with
  366. :djadmin:`startproject`. If you want to use this feature in an existing
  367. project, read the :ref:`migration guide <time-zones-migration-guide>`.
  368. HTML comparisons in tests
  369. ~~~~~~~~~~~~~~~~~~~~~~~~~
  370. The :class:`~django.test.testcase.TestCase` base class now has some helpers to
  371. compare HTML without tripping over irrelevant differences in whitespace,
  372. argument quoting/ordering and closing of self-closing tags. You can either
  373. compare HTML directly with the new
  374. :meth:`~django.test.testcase.TestCase.assertHTMLEqual` and
  375. :meth:`~django.test.testcase.TestCase.assertHTMLNotEqual` assertions, or use
  376. the ``html=True`` flag with
  377. :meth:`~django.test.testcase.TestCase.assertContains` and
  378. :meth:`~django.test.testcase.TestCase.assertNotContains` to test whether the
  379. client's response contains a given HTML fragment. See the :ref:`assertion
  380. documentation<assertions>` for more.
  381. Two new date format strings
  382. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  383. Two new :tfilter:`date` formats were added for use in template filters,
  384. template tags and :ref:`format-localization`:
  385. - ``e`` -- the name of the timezone of the given datetime object
  386. - ``o`` -- the ISO 8601 year number
  387. Please make sure to update your :ref:`custom format files
  388. <custom-format-files>` if they contain either ``e`` or ``o`` in a format
  389. string. For example a Spanish localization format previously only escaped the
  390. ``d`` format character::
  391. DATE_FORMAT = r'j \de F \de Y'
  392. But now it needs to also escape ``e`` and ``o``::
  393. DATE_FORMAT = r'j \d\e F \d\e Y'
  394. For more information, see the :tfilter:`date` documentation.
  395. Minor features
  396. ~~~~~~~~~~~~~~
  397. Django 1.4 also includes several smaller improvements worth noting:
  398. * A more usable stacktrace in the technical 500 page. Frames in the
  399. stack trace that reference Django's framework code are dimmed out,
  400. while frames in application code are slightly emphasized. This change
  401. makes it easier to scan a stacktrace for issues in application code.
  402. * :doc:`Tablespace support </topics/db/tablespaces>` in PostgreSQL.
  403. * Customizable names for :meth:`~django.template.Library.simple_tag`.
  404. * In the documentation, a helpful :doc:`security overview </topics/security>`
  405. page.
  406. * The :func:`django.contrib.auth.models.check_password` function has been moved
  407. to the :mod:`django.contrib.auth.utils` module. Importing it from the old
  408. location will still work, but you should update your imports.
  409. * The :djadmin:`collectstatic` management command now has a ``--clear`` option
  410. to delete all files at the destination before copying or linking the static
  411. files.
  412. * It's now possible to load fixtures containing forward references when using
  413. MySQL with the InnoDB database engine.
  414. * A new 403 response handler has been added as
  415. ``'django.views.defaults.permission_denied'``. You can set your own handler by
  416. setting the value of :data:`django.conf.urls.handler403`. See the
  417. documentation about :ref:`the 403 (HTTP Forbidden) view<http_forbidden_view>`
  418. for more information.
  419. * The :djadmin:`makemessages` command uses a new and more accurate lexer,
  420. `JsLex`_, for extracting translatable strings from JavaScript files.
  421. .. _JsLex: https://bitbucket.org/ned/jslex
  422. * The :ttag:`trans` template tag now takes an optional ``as`` argument to
  423. be able to retrieve a translation string without displaying it but setting
  424. a template context variable instead.
  425. * The :ttag:`if` template tag now supports ``{% elif %}`` clauses.
  426. * If your Django app is behind a proxy, you might find the new
  427. :setting:`SECURE_PROXY_SSL_HEADER` setting useful. It solves the problem of your
  428. proxy "eating" the fact that a request came in via HTTPS. But only use this
  429. setting if you know what you're doing.
  430. * A new, plain-text, version of the HTTP 500 status code internal error page
  431. served when :setting:`DEBUG` is ``True`` is now sent to the client when
  432. Django detects that the request has originated in JavaScript code.
  433. (:meth:`~django.http.HttpRequest.is_ajax` is used for this.)
  434. Like its HTML counterpart, it contains a collection of different
  435. pieces of information about the state of the application.
  436. This should make it easier to read when debugging interaction with
  437. client-side JavaScript.
  438. * Added the :djadminopt:`--no-location` option to the :djadmin:`makemessages`
  439. command.
  440. * Changed the ``locmem`` cache backend to use
  441. ``pickle.HIGHEST_PROTOCOL`` for better compatibility with the other
  442. cache backends.
  443. * Added support in the ORM for generating ``SELECT`` queries containing
  444. ``DISTINCT ON``.
  445. The ``distinct()`` ``QuerySet`` method now accepts an optional list of model
  446. field names. If specified, then the ``DISTINCT`` statement is limited to these
  447. fields. This is only supported in PostgreSQL.
  448. For more details, see the documentation for
  449. :meth:`~django.db.models.query.QuerySet.distinct`.
  450. * The admin login page will add a password reset link if you include a URL with
  451. the name `'admin_password_reset'` in your urls.py, so plugging in the built-in
  452. password reset mechanism and making it available is now much easier. For
  453. details, see :ref:`auth_password_reset`.
  454. * The MySQL database backend can now make use of the savepoint feature
  455. implemented by MySQL version 5.0.3 or newer with the InnoDB storage engine.
  456. * It's now possible to pass initial values to the model forms that are part of
  457. both model formsets and inline model formsets as returned from factory
  458. functions ``modelformset_factory`` and ``inlineformset_factory`` respectively
  459. just like with regular formsets. However, initial values only apply to extra
  460. forms, i.e. those which are not bound to an existing model instance.
  461. * The sitemaps framework can now handle HTTPS links using the new
  462. :attr:`Sitemap.protocol <django.contrib.sitemaps.Sitemap.protocol>` class
  463. attribute.
  464. Backwards incompatible changes in 1.4
  465. =====================================
  466. django.contrib.admin
  467. ~~~~~~~~~~~~~~~~~~~~
  468. The included administration app ``django.contrib.admin`` has for a long time
  469. shipped with a default set of static files such as JavaScript, images and
  470. stylesheets. Django 1.3 added a new contrib app ``django.contrib.staticfiles``
  471. to handle such files in a generic way and defined conventions for static
  472. files included in apps.
  473. Starting in Django 1.4, the admin's static files also follow this
  474. convention, to make the files easier to deploy. In previous versions of Django,
  475. it was also common to define an ``ADMIN_MEDIA_PREFIX`` setting to point to the
  476. URL where the admin's static files live on a Web server. This setting has now
  477. been deprecated and replaced by the more general setting :setting:`STATIC_URL`.
  478. Django will now expect to find the admin static files under the URL
  479. ``<STATIC_URL>/admin/``.
  480. If you've previously used a URL path for ``ADMIN_MEDIA_PREFIX`` (e.g.
  481. ``/media/``) simply make sure :setting:`STATIC_URL` and :setting:`STATIC_ROOT`
  482. are configured and your Web server serves those files correctly. The
  483. development server continues to serve the admin files just like before. Read
  484. the :doc:`static files howto </howto/static-files>` for more details.
  485. If your ``ADMIN_MEDIA_PREFIX`` is set to an specific domain (e.g.
  486. ``http://media.example.com/admin/``), make sure to also set your
  487. :setting:`STATIC_URL` setting to the correct URL -- for example,
  488. ``http://media.example.com/``.
  489. .. warning::
  490. If you're implicitly relying on the path of the admin static files within
  491. Django's source code, you'll need to update that path. The files were moved
  492. from :file:`django/contrib/admin/media/` to
  493. :file:`django/contrib/admin/static/admin/`.
  494. Supported browsers for the admin
  495. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  496. Django hasn't had a clear policy on which browsers are supported by the
  497. admin app. Our new policy formalizes existing practices: `YUI's A-grade`_
  498. browsers should provide a fully-functional admin experience, with the notable
  499. exception of Internet Explorer 6, which is no longer supported.
  500. Released over 10 years ago, IE6 imposes many limitations on modern Web
  501. development. The practical implications of this policy are that contributors
  502. are free to improve the admin without consideration for these limitations.
  503. Obviously, this new policy **has no impact** on sites you develop using Django.
  504. It only applies to the Django admin. Feel free to develop apps compatible with
  505. any range of browsers.
  506. .. _YUI's A-grade: http://yuilibrary.com/yui/docs/tutorials/gbs/
  507. Removed admin icons
  508. ~~~~~~~~~~~~~~~~~~~
  509. As part of an effort to improve the performance and usability of the admin's
  510. change-list sorting interface and :attr:`horizontal
  511. <django.contrib.admin.ModelAdmin.filter_horizontal>` and :attr:`vertical
  512. <django.contrib.admin.ModelAdmin.filter_vertical>` "filter" widgets, some icon
  513. files were removed and grouped into two sprite files.
  514. Specifically: ``selector-add.gif``, ``selector-addall.gif``,
  515. ``selector-remove.gif``, ``selector-removeall.gif``,
  516. ``selector_stacked-add.gif`` and ``selector_stacked-remove.gif`` were
  517. combined into ``selector-icons.gif``; and ``arrow-up.gif`` and
  518. ``arrow-down.gif`` were combined into ``sorting-icons.gif``.
  519. If you used those icons to customize the admin, then you'll need to replace
  520. them with your own icons or get the files from a previous release.
  521. CSS class names in admin forms
  522. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  523. To avoid conflicts with other common CSS class names (e.g. "button"), we added
  524. a prefix ("field-") to all CSS class names automatically generated from the
  525. form field names in the main admin forms, stacked inline forms and tabular
  526. inline cells. You'll need to take that prefix into account in your custom
  527. style sheets or JavaScript files if you previously used plain field names as
  528. selectors for custom styles or JavaScript transformations.
  529. Compatibility with old signed data
  530. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  531. Django 1.3 changed the cryptographic signing mechanisms used in a number of
  532. places in Django. While Django 1.3 kept fallbacks that would accept hashes
  533. produced by the previous methods, these fallbacks are removed in Django 1.4.
  534. So, if you upgrade to Django 1.4 directly from 1.2 or earlier, you may
  535. lose/invalidate certain pieces of data that have been cryptographically signed
  536. using an old method. To avoid this, use Django 1.3 first for a period of time
  537. to allow the signed data to expire naturally. The affected parts are detailed
  538. below, with 1) the consequences of ignoring this advice and 2) the amount of
  539. time you need to run Django 1.3 for the data to expire or become irrelevant.
  540. * ``contrib.sessions`` data integrity check
  541. * Consequences: The user will be logged out, and session data will be lost.
  542. * Time period: Defined by :setting:`SESSION_COOKIE_AGE`.
  543. * ``contrib.auth`` password reset hash
  544. * Consequences: Password reset links from before the upgrade will not work.
  545. * Time period: Defined by :setting:`PASSWORD_RESET_TIMEOUT_DAYS`.
  546. Form-related hashes: these have a are much shorter lifetime and are relevant
  547. only for the short window where a user might fill in a form generated by the
  548. pre-upgrade Django instance and try to submit it to the upgraded Django
  549. instance:
  550. * ``contrib.comments`` form security hash
  551. * Consequences: The user will see the validation error "Security hash failed."
  552. * Time period: The amount of time you expect users to take filling out comment
  553. forms.
  554. * ``FormWizard`` security hash
  555. * Consequences: The user will see an error about the form having expired
  556. and will be sent back to the first page of the wizard, losing the data
  557. he has entered so far.
  558. * Time period: The amount of time you expect users to take filling out the
  559. affected forms.
  560. * CSRF check
  561. * Note: This is actually a Django 1.1 fallback, not Django 1.2,
  562. and it applies only if you're upgrading from 1.1.
  563. * Consequences: The user will see a 403 error with any CSRF-protected POST
  564. form.
  565. * Time period: The amount of time you expect user to take filling out
  566. such forms.
  567. django.contrib.flatpages
  568. ~~~~~~~~~~~~~~~~~~~~~~~~
  569. Starting in 1.4, the
  570. :class:`~django.contrib.flatpages.middleware.FlatpageFallbackMiddleware` only
  571. adds a trailing slash and redirects if the resulting URL refers to an existing
  572. flatpage. For example, requesting ``/notaflatpageoravalidurl`` in a previous
  573. version would redirect to ``/notaflatpageoravalidurl/``, which would
  574. subsequently raise a 404. Requesting ``/notaflatpageoravalidurl`` now will
  575. immediately raise a 404.
  576. Also, redirects returned by flatpages are now permanent (with 301 status code),
  577. to match the behavior of :class:`~django.middleware.common.CommonMiddleware`.
  578. Serialization of :class:`~datetime.datetime` and :class:`~datetime.time`
  579. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  580. As a consequence of time-zone support, and according to the ECMA-262
  581. specification, we made changes to the JSON serializer:
  582. * It includes the time zone for aware datetime objects. It raises an exception
  583. for aware time objects.
  584. * It includes milliseconds for datetime and time objects. There is still
  585. some precision loss, because Python stores microseconds (6 digits) and JSON
  586. only supports milliseconds (3 digits). However, it's better than discarding
  587. microseconds entirely.
  588. We changed the XML serializer to use the ISO8601 format for datetimes.
  589. The letter ``T`` is used to separate the date part from the time part, instead
  590. of a space. Time zone information is included in the ``[+-]HH:MM`` format.
  591. Though the serializers now use these new formats when creating fixtures, they
  592. can still load fixtures that use the old format.
  593. ``supports_timezone`` changed to ``False`` for SQLite
  594. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  595. The database feature ``supports_timezone`` used to be ``True`` for SQLite.
  596. Indeed, if you saved an aware datetime object, SQLite stored a string that
  597. included an UTC offset. However, this offset was ignored when loading the value
  598. back from the database, which could corrupt the data.
  599. In the context of time-zone support, this flag was changed to ``False``, and
  600. datetimes are now stored without time-zone information in SQLite. When
  601. :setting:`USE_TZ` is ``False``, if you attempt to save an aware datetime
  602. object, Django raises an exception.
  603. ``MySQLdb``-specific exceptions
  604. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  605. The MySQL backend historically has raised :class:`MySQLdb.OperationalError`
  606. when a query triggered an exception. We've fixed this bug, and we now raise
  607. :class:`django.db.utils.DatabaseError` instead. If you were testing for
  608. :class:`MySQLdb.OperationalError`, you'll need to update your ``except``
  609. clauses.
  610. Database connection's thread-locality
  611. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  612. ``DatabaseWrapper`` objects (i.e. the connection objects referenced by
  613. ``django.db.connection`` and ``django.db.connections["some_alias"]``) used to
  614. be thread-local. They are now global objects in order to be potentially shared
  615. between multiple threads. While the individual connection objects are now
  616. global, the ``django.db.connections`` dictionary referencing those objects is
  617. still thread-local. Therefore if you just use the ORM or
  618. ``DatabaseWrapper.cursor()`` then the behavior is still the same as before.
  619. Note, however, that ``django.db.connection`` does not directly reference the
  620. default ``DatabaseWrapper`` object anymore and is now a proxy to access that
  621. object's attributes. If you need to access the actual ``DatabaseWrapper``
  622. object, use ``django.db.connections[DEFAULT_DB_ALIAS]`` instead.
  623. As part of this change, all underlying SQLite connections are now enabled for
  624. potential thread-sharing (by passing the ``check_same_thread=False`` attribute
  625. to pysqlite). ``DatabaseWrapper`` however preserves the previous behavior by
  626. disabling thread-sharing by default, so this does not affect any existing
  627. code that purely relies on the ORM or on ``DatabaseWrapper.cursor()``.
  628. Finally, while it's now possible to pass connections between threads, Django
  629. doesn't make any effort to synchronize access to the underlying backend.
  630. Concurrency behavior is defined by the underlying backend implementation.
  631. Check their documentation for details.
  632. `COMMENTS_BANNED_USERS_GROUP` setting
  633. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  634. Django's :doc:`comments app </ref/contrib/comments/index>` has historically
  635. supported excluding the comments of a special user group, but we've never
  636. documented the feature properly and didn't enforce the exclusion in other parts
  637. of the app such as the template tags. To fix this problem, we removed the code
  638. from the feed class.
  639. If you rely on the feature and want to restore the old behavior, use a custom
  640. comment model manager to exclude the user group, like this::
  641. from django.conf import settings
  642. from django.contrib.comments.managers import CommentManager
  643. class BanningCommentManager(CommentManager):
  644. def get_query_set(self):
  645. qs = super(BanningCommentManager, self).get_query_set()
  646. if getattr(settings, 'COMMENTS_BANNED_USERS_GROUP', None):
  647. where = ['user_id NOT IN (SELECT user_id FROM auth_user_groups WHERE group_id = %s)']
  648. params = [settings.COMMENTS_BANNED_USERS_GROUP]
  649. qs = qs.extra(where=where, params=params)
  650. return qs
  651. Save this model manager in your custom comment app (e.g., in
  652. ``my_comments_app/managers.py``) and add it your
  653. :ref:`custom comment app model <custom-comment-app-api>`::
  654. from django.db import models
  655. from django.contrib.comments.models import Comment
  656. from my_comments_app.managers import BanningCommentManager
  657. class CommentWithTitle(Comment):
  658. title = models.CharField(max_length=300)
  659. objects = BanningCommentManager()
  660. For more details, see the documentation about
  661. :doc:`customizing the comments framework </ref/contrib/comments/custom>`.
  662. `IGNORABLE_404_STARTS` and `IGNORABLE_404_ENDS` settings
  663. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  664. Until Django 1.3, it was possible to exclude some URLs from Django's
  665. :doc:`404 error reporting</howto/error-reporting>` by adding prefixes to
  666. :setting:`IGNORABLE_404_STARTS` and suffixes to :setting:`IGNORABLE_404_ENDS`.
  667. In Django 1.4, these two settings are superseded by
  668. :setting:`IGNORABLE_404_URLS`, which is a list of compiled regular expressions.
  669. Django won't send an email for 404 errors on URLs that match any of them.
  670. Furthermore, the previous settings had some rather arbitrary default values::
  671. IGNORABLE_404_STARTS = ('/cgi-bin/', '/_vti_bin', '/_vti_inf')
  672. IGNORABLE_404_ENDS = ('mail.pl', 'mailform.pl', 'mail.cgi', 'mailform.cgi',
  673. 'favicon.ico', '.php')
  674. It's not Django's role to decide if your website has a legacy ``/cgi-bin/``
  675. section or a ``favicon.ico``. As a consequence, the default values of
  676. :setting:`IGNORABLE_404_URLS`, :setting:`IGNORABLE_404_STARTS` and
  677. :setting:`IGNORABLE_404_ENDS` are all now empty.
  678. If you have customized :setting:`IGNORABLE_404_STARTS` or
  679. :setting:`IGNORABLE_404_ENDS`, or if you want to keep the old default value,
  680. you should add the following lines in your settings file::
  681. import re
  682. IGNORABLE_404_URLS = (
  683. # for each <prefix> in IGNORABLE_404_STARTS
  684. re.compile(r'^<prefix>'),
  685. # for each <suffix> in IGNORABLE_404_ENDS
  686. re.compile(r'<suffix>$'),
  687. )
  688. Don't forget to escape characters that have a special meaning in a regular
  689. expression, such as periods.
  690. CSRF protection extended to PUT and DELETE
  691. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  692. Previously, Django's :doc:`CSRF protection </ref/contrib/csrf/>` provided
  693. protection only against POST requests. Since use of PUT and DELETE methods in
  694. AJAX applications is becoming more common, we now protect all methods not
  695. defined as safe by :rfc:`2616` -- i.e., we exempt GET, HEAD, OPTIONS and TRACE,
  696. and we enforce protection on everything else.
  697. If you're using PUT or DELETE methods in AJAX applications, please see the
  698. :ref:`instructions about using AJAX and CSRF <csrf-ajax>`.
  699. ``django.core.template_loaders``
  700. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  701. This was an alias to ``django.template.loader`` since 2005, and we've removed it
  702. without emitting a warning due to the length of the deprecation. If your code
  703. still referenced this, please use ``django.template.loader`` instead.
  704. ``django.db.models.fields.URLField.verify_exists``
  705. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  706. This functionality has been removed due to intractable performance and
  707. security issues. Any existing usage of ``verify_exists`` should be
  708. removed.
  709. ``django.core.files.storage.Storage.open``
  710. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  711. The ``open`` method of the base Storage class used to take an obscure parameter
  712. ``mixin`` that allowed you to dynamically change the base classes of the
  713. returned file object. This has been removed. In the rare case you relied on the
  714. `mixin` parameter, you can easily achieve the same by overriding the `open`
  715. method, like this::
  716. from django.core.files import File
  717. from django.core.files.storage import FileSystemStorage
  718. class Spam(File):
  719. """
  720. Spam, spam, spam, spam and spam.
  721. """
  722. def ham(self):
  723. return 'eggs'
  724. class SpamStorage(FileSystemStorage):
  725. """
  726. A custom file storage backend.
  727. """
  728. def open(self, name, mode='rb'):
  729. return Spam(open(self.path(name), mode))
  730. YAML deserializer now uses ``yaml.safe_load``
  731. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  732. ``yaml.load`` is able to construct any Python object, which may trigger
  733. arbitrary code execution if you process a YAML document that comes from an
  734. untrusted source. This feature isn't necessary for Django's YAML deserializer,
  735. whose primary use is to load fixtures consisting of simple objects. Even though
  736. fixtures are trusted data, the YAML deserializer now uses ``yaml.safe_load``
  737. for additional security.
  738. Session cookies now have the ``httponly`` flag by default
  739. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  740. Session cookies now include the ``httponly`` attribute by default to
  741. help reduce the impact of potential XSS attacks. For strict backwards
  742. compatibility, use ``SESSION_COOKIE_HTTPONLY = False`` in your settings file.
  743. The :tfilter:`urlize` filter no longer escapes every URL
  744. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  745. When a URL contains a ``%xx`` sequence, where ``xx`` are two hexadecimal
  746. digits, :tfilter:`urlize` now assumes that the URL is already escaped and
  747. doesn't apply URL escaping again. This is wrong for URLs whose unquoted form
  748. contains a ``%xx`` sequence, but such URLs are very unlikely to happen in the
  749. wild, because they would confuse browsers too.
  750. ``assertTemplateUsed`` and ``assertTemplateNotUsed`` as context manager
  751. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  752. It's now possible to check whether a template was used within a block of
  753. code with :meth:`~django.test.testcase.TestCase.assertTemplateUsed` and
  754. :meth:`~django.test.testcase.TestCase.assertTemplateNotUsed`. And they
  755. can be used as a context manager::
  756. with self.assertTemplateUsed('index.html'):
  757. render_to_string('index.html')
  758. with self.assertTemplateNotUsed('base.html'):
  759. render_to_string('index.html')
  760. See the :ref:`assertion documentation<assertions>` for more.
  761. Database connections after running the test suite
  762. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  763. The default test runner no longer restores the database connections after
  764. tests' execution. This prevents the production database from being exposed to
  765. potential threads that would still be running and attempting to create new
  766. connections.
  767. If your code relied on connections to the production database being created
  768. after tests' execution, then you can restore the previous behavior by
  769. subclassing ``DjangoTestRunner`` and overriding its ``teardown_databases()``
  770. method.
  771. Output of :djadmin:`manage.py help <help>`
  772. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  773. :djadmin:`manage.py help <help>` now groups available commands by application.
  774. If you depended on the output of this command -- if you parsed it, for example
  775. -- then you'll need to update your code. To get a list of all available
  776. management commands in a script, use
  777. :djadmin:`manage.py help --commands <help>` instead.
  778. Features deprecated in 1.4
  779. ==========================
  780. Old styles of calling ``cache_page`` decorator
  781. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  782. Some legacy ways of calling :func:`~django.views.decorators.cache.cache_page`
  783. have been deprecated. Please see the documentation for the correct way to use
  784. this decorator.
  785. Support for PostgreSQL versions older than 8.2
  786. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  787. Django 1.3 dropped support for PostgreSQL versions older than 8.0, and we
  788. suggested using a more recent version because of performance improvements
  789. and, more importantly, the end of upstream support periods for 8.0 and 8.1
  790. was near (November 2010).
  791. Django 1.4 takes that policy further and sets 8.2 as the minimum PostgreSQL
  792. version it officially supports.
  793. Request exceptions are now always logged
  794. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  795. When we added :doc:`logging support </topics/logging/>` in Django in 1.3, the
  796. admin error email support was moved into the
  797. :class:`django.utils.log.AdminEmailHandler`, attached to the
  798. ``'django.request'`` logger. In order to maintain the established behavior of
  799. error emails, the ``'django.request'`` logger was called only when
  800. :setting:`DEBUG` was ``False``.
  801. To increase the flexibility of error logging for requests, the
  802. ``'django.request'`` logger is now called regardless of the value of
  803. :setting:`DEBUG`, and the default settings file for new projects now includes a
  804. separate filter attached to :class:`django.utils.log.AdminEmailHandler` to
  805. prevent admin error emails in ``DEBUG`` mode::
  806. 'filters': {
  807. 'require_debug_false': {
  808. '()': 'django.utils.log.RequireDebugFalse'
  809. }
  810. },
  811. 'handlers': {
  812. 'mail_admins': {
  813. 'level': 'ERROR',
  814. 'filters': ['require_debug_false'],
  815. 'class': 'django.utils.log.AdminEmailHandler'
  816. }
  817. },
  818. If your project was created prior to this change, your :setting:`LOGGING`
  819. setting will not include this new filter. In order to maintain
  820. backwards-compatibility, Django will detect that your ``'mail_admins'`` handler
  821. configuration includes no ``'filters'`` section and will automatically add
  822. this filter for you and issue a pending-deprecation warning. This will become a
  823. deprecation warning in Django 1.5, and in Django 1.6 the
  824. backwards-compatibility shim will be removed entirely.
  825. The existence of any ``'filters'`` key under the ``'mail_admins'`` handler will
  826. disable this backward-compatibility shim and deprecation warning.
  827. ``django.conf.urls.defaults``
  828. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  829. Until Django 1.3, the functions :func:`~django.conf.urls.include`,
  830. :func:`~django.conf.urls.patterns` and :func:`~django.conf.urls.url` plus
  831. :data:`~django.conf.urls.handler404`, :data:`~django.conf.urls.handler500`
  832. were located in a ``django.conf.urls.defaults`` module.
  833. In Django 1.4, they live in :mod:`django.conf.urls`.
  834. ``django.contrib.databrowse``
  835. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  836. Databrowse has not seen active development for some time, and this does not show
  837. any sign of changing. There had been a suggestion for a `GSOC project`_ to
  838. integrate the functionality of databrowse into the admin, but no progress was
  839. made. While Databrowse has been deprecated, an enhancement of
  840. ``django.contrib.admin`` providing a similar feature set is still possible.
  841. .. _GSOC project: https://code.djangoproject.com/wiki/SummerOfCode2011#Integratedatabrowseintotheadmin
  842. The code that powers Databrowse is licensed under the same terms as Django
  843. itself, so it's available to be adopted by an individual or group as
  844. a third-party project.
  845. ``django.core.management.setup_environ``
  846. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  847. This function temporarily modified ``sys.path`` in order to make the parent
  848. "project" directory importable under the old flat :djadmin:`startproject`
  849. layout. This function is now deprecated, as its path workarounds are no longer
  850. needed with the new ``manage.py`` and default project layout.
  851. This function was never documented or part of the public API, but it was widely
  852. recommended for use in setting up a "Django environment" for a user script.
  853. These uses should be replaced by setting the ``DJANGO_SETTINGS_MODULE``
  854. environment variable or using :func:`django.conf.settings.configure`.
  855. ``django.core.management.execute_manager``
  856. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  857. This function was previously used by ``manage.py`` to execute a management
  858. command. It is identical to
  859. ``django.core.management.execute_from_command_line``, except that it first
  860. calls ``setup_environ``, which is now deprecated. As such, ``execute_manager``
  861. is also deprecated; ``execute_from_command_line`` can be used instead. Neither
  862. of these functions is documented as part of the public API, but a deprecation
  863. path is needed due to use in existing ``manage.py`` files.
  864. ``is_safe`` and ``needs_autoescape`` attributes of template filters
  865. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  866. Two flags, ``is_safe`` and ``needs_autoescape``, define how each template filter
  867. interacts with Django's auto-escaping behavior. They used to be attributes of
  868. the filter function::
  869. @register.filter
  870. def noop(value):
  871. return value
  872. noop.is_safe = True
  873. However, this technique caused some problems in combination with decorators,
  874. especially :func:`@stringfilter <django.template.defaultfilters.stringfilter>`.
  875. Now, the flags are keyword arguments of :meth:`@register.filter
  876. <django.template.Library.filter>`::
  877. @register.filter(is_safe=True)
  878. def noop(value):
  879. return value
  880. See :ref:`filters and auto-escaping <filters-auto-escaping>` for more information.
  881. Wildcard expansion of application names in `INSTALLED_APPS`
  882. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  883. Until Django 1.3, :setting:`INSTALLED_APPS` accepted wildcards in application
  884. names, like ``django.contrib.*``. The expansion was performed by a
  885. filesystem-based implementation of ``from <package> import *``. Unfortunately,
  886. `this can't be done reliably`_.
  887. This behavior was never documented. Since it is un-pythonic and not obviously
  888. useful, it was removed in Django 1.4. If you relied on it, you must edit your
  889. settings file to list all your applications explicitly.
  890. .. _this can't be done reliably: http://docs.python.org/tutorial/modules.html#importing-from-a-package
  891. ``HttpRequest.raw_post_data`` renamed to ``HttpRequest.body``
  892. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  893. This attribute was confusingly named ``HttpRequest.raw_post_data``, but it
  894. actually provided the body of the HTTP request. It's been renamed to
  895. ``HttpRequest.body``, and ``HttpRequest.raw_post_data`` has been deprecated.
  896. ``django.contrib.sitemaps`` bug fix with potential performance implications
  897. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  898. In previous versions, ``Paginator`` objects used in sitemap classes were
  899. cached, which could result in stale site maps. We've removed the caching, so
  900. each request to a site map now creates a new Paginator object and calls the
  901. :attr:`~django.contrib.sitemaps.Sitemap.items()` method of the
  902. :class:`~django.contrib.sitemaps.Sitemap` subclass. Depending on what your
  903. ``items()`` method is doing, this may have a negative performance impact.
  904. To mitigate the performance impact, consider using the :doc:`caching
  905. framework </topics/cache>` within your ``Sitemap`` subclass.