1.4.txt 56 KB

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