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