1.4.txt 57 KB

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