1.9.txt 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. ============================================
  2. Django 1.9 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. Welcome to Django 1.9!
  5. These release notes cover the `new features`_, as well as some `backwards
  6. incompatible changes`_ you'll want to be aware of when upgrading from Django
  7. 1.8 or older versions. We've :ref:`dropped some features<removed-features-1.9>`
  8. that have reached the end of their deprecation cycle, and we've `begun the
  9. deprecation process for some features`_.
  10. .. _`new features`: `What's new in Django 1.9`_
  11. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.9`_
  12. .. _`dropped some features`: `Features removed in 1.9`_
  13. .. _`begun the deprecation process for some features`: `Features deprecated in 1.9`_
  14. Python compatibility
  15. ====================
  16. Django 1.9 requires Python 2.7, 3.4, or 3.5. We **highly recommend** and only
  17. officially support the latest release of each series.
  18. Since Django 1.8, we've dropped support for Python 3.2 and 3.3, and added
  19. support for Python 3.5.
  20. What's new in Django 1.9
  21. ========================
  22. Performing actions after a transaction commit
  23. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. The new :func:`~django.db.transaction.on_commit` hook allows performing actions
  25. after a database transaction is successfully committed. This is useful for
  26. tasks such as sending notification emails, creating queued tasks, or
  27. invalidating caches.
  28. This functionality from the `django-transaction-hooks`_ package has been
  29. integrated into Django.
  30. .. _django-transaction-hooks: https://pypi.python.org/pypi/django-transaction-hooks
  31. Password validation
  32. ~~~~~~~~~~~~~~~~~~~
  33. Django now offers password validation to help prevent the usage of weak
  34. passwords by users. The validation is integrated in the included password
  35. change and reset forms and is simple to integrate in any other code.
  36. Validation is performed by one or more validators, configured in the new
  37. :setting:`AUTH_PASSWORD_VALIDATORS` setting.
  38. Four validators are included in Django, which can enforce a minimum length,
  39. compare the password to the user's attributes like their name, ensure
  40. passwords aren't entirely numeric, or check against an included list of common
  41. passwords. You can combine multiple validators, and some validators have
  42. custom configuration options. For example, you can choose to provide a custom
  43. list of common passwords. Each validator provides a help text to explain its
  44. requirements to the user.
  45. By default, no validation is performed and all passwords are accepted, so if
  46. you don't set :setting:`AUTH_PASSWORD_VALIDATORS`, you will not see any
  47. change. In new projects created with the default :djadmin:`startproject`
  48. template, a simple set of validators is enabled. To enable basic validation in
  49. the included auth forms for your project, you could set, for example::
  50. AUTH_PASSWORD_VALIDATORS = [
  51. {
  52. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  53. },
  54. {
  55. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  56. },
  57. {
  58. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  59. },
  60. {
  61. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  62. },
  63. ]
  64. See :ref:`password-validation` for more details.
  65. Permission mixins for class-based views
  66. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. Django now ships with the mixins
  68. :class:`~django.contrib.auth.mixins.AccessMixin`,
  69. :class:`~django.contrib.auth.mixins.LoginRequiredMixin`,
  70. :class:`~django.contrib.auth.mixins.PermissionRequiredMixin`, and
  71. :class:`~django.contrib.auth.mixins.UserPassesTestMixin` to provide the
  72. functionality of the ``django.contrib.auth.decorators`` for class-based views.
  73. These mixins have been taken from, or are at least inspired by, the
  74. `django-braces`_ project.
  75. There are a few differences between Django's and django-braces' implementation,
  76. though:
  77. * The :attr:`~django.contrib.auth.mixins.AccessMixin.raise_exception` attribute
  78. can only be ``True`` or ``False``. Custom exceptions or callables are not
  79. supported.
  80. * The :meth:`~django.contrib.auth.mixins.AccessMixin.handle_no_permission`
  81. method does not take a ``request`` argument. The current request is available
  82. in ``self.request``.
  83. * The custom ``test_func()`` of :class:`~django.contrib.auth.mixins.UserPassesTestMixin`
  84. does not take a ``user`` argument. The current user is available in
  85. ``self.request.user``.
  86. * The :attr:`permission_required <django.contrib.auth.mixins.PermissionRequiredMixin>`
  87. attribute supports a string (defining one permission) or a list/tuple of
  88. strings (defining multiple permissions) that need to be fulfilled to grant
  89. access.
  90. * The new :attr:`~django.contrib.auth.mixins.AccessMixin.permission_denied_message`
  91. attribute allows passing a message to the ``PermissionDenied`` exception.
  92. .. _django-braces: http://django-braces.readthedocs.org/en/latest/index.html
  93. New styling for ``contrib.admin``
  94. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. The admin sports a modern, flat design with new SVG icons which look perfect
  96. on HiDPI screens. It still provides a fully-functional experience to `YUI's
  97. A-grade`_ browsers. Older browser may experience varying levels of graceful
  98. degradation.
  99. .. _YUI's A-grade: https://github.com/yui/yui3/wiki/Graded-Browser-Support
  100. Running tests in parallel
  101. ~~~~~~~~~~~~~~~~~~~~~~~~~
  102. The :djadmin:`test` command now supports a :djadminopt:`--parallel` option to
  103. run a project's tests in multiple processes in parallel.
  104. Each process gets its own database. You must ensure that different test cases
  105. don't access the same resources. For instance, test cases that touch the
  106. filesystem should create a temporary directory for their own use.
  107. This option is enabled by default for Django's own test suite provided:
  108. - the OS supports it (all but Windows)
  109. - the database backend supports it (all the built-in backends but Oracle)
  110. Minor features
  111. ~~~~~~~~~~~~~~
  112. :mod:`django.contrib.admin`
  113. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  114. * Admin views now have ``model_admin`` or ``admin_site`` attributes.
  115. * The URL of the admin change view has been changed (was at
  116. ``/admin/<app>/<model>/<pk>/`` by default and is now at
  117. ``/admin/<app>/<model>/<pk>/change/``). This should not affect your
  118. application unless you have hardcoded admin URLs. In that case, replace those
  119. links by :ref:`reversing admin URLs <admin-reverse-urls>` instead. Note that
  120. the old URL still redirects to the new one for backwards compatibility, but
  121. it may be removed in a future version.
  122. * :meth:`ModelAdmin.get_list_select_related()
  123. <django.contrib.admin.ModelAdmin.get_list_select_related>` was added to allow
  124. changing the ``select_related()`` values used in the admin's changelist query
  125. based on the request.
  126. * The ``available_apps`` context variable, which lists the available
  127. applications for the current user, has been added to the
  128. :meth:`AdminSite.each_context() <django.contrib.admin.AdminSite.each_context>`
  129. method.
  130. * :attr:`AdminSite.empty_value_display
  131. <django.contrib.admin.AdminSite.empty_value_display>` and
  132. :attr:`ModelAdmin.empty_value_display
  133. <django.contrib.admin.ModelAdmin.empty_value_display>` were added to override
  134. the display of empty values in admin change list. You can also customize the
  135. value for each field.
  136. * The time picker widget includes a '6 p.m' option for consistency of having
  137. predefined options every 6 hours.
  138. * JavaScript slug generation now supports Romanian characters.
  139. :mod:`django.contrib.admindocs`
  140. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  141. * The model section of the ``admindocs`` now also describes methods that take
  142. arguments, rather than ignoring them.
  143. :mod:`django.contrib.auth`
  144. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  145. * The default iteration count for the PBKDF2 password hasher has been increased
  146. by 20%. This backwards compatible change will not affect users who have
  147. subclassed ``django.contrib.auth.hashers.PBKDF2PasswordHasher`` to change the
  148. default value.
  149. * The ``BCryptSHA256PasswordHasher`` will now update passwords if its
  150. ``rounds`` attribute is changed.
  151. * ``AbstractBaseUser`` and ``BaseUserManager`` were moved to a new
  152. ``django.contrib.auth.base_user`` module so that they can be imported without
  153. including ``django.contrib.auth`` in :setting:`INSTALLED_APPS` (doing so
  154. raised a deprecation warning in older versions and is no longer supported in
  155. Django 1.9).
  156. * The permission argument of
  157. :func:`~django.contrib.auth.decorators.permission_required()` accepts all
  158. kinds of iterables, not only list and tuples.
  159. * The new :class:`~django.contrib.auth.middleware.PersistentRemoteUserMiddleware`
  160. makes it possible to use ``REMOTE_USER`` for setups where the header is only
  161. populated on login pages instead of every request in the session.
  162. * The :func:`~django.contrib.auth.views.password_reset` view accepts an
  163. ``extra_email_context`` parameter.
  164. :mod:`django.contrib.contenttypes`
  165. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  166. * It's now possible to use
  167. :attr:`~django.db.models.Options.order_with_respect_to` with a
  168. ``GenericForeignKey``.
  169. :mod:`django.contrib.gis`
  170. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  171. * All ``GeoQuerySet`` methods have been deprecated and replaced by
  172. :doc:`equivalent database functions </ref/contrib/gis/functions>`. As soon
  173. as the legacy methods have been replaced in your code, you should even be
  174. able to remove the special ``GeoManager`` from your GIS-enabled classes.
  175. * The GDAL interface now supports instantiating file-based and in-memory
  176. :ref:`GDALRaster objects <raster-data-source-objects>` from raw data.
  177. Setters for raster properties such as projection or pixel values have
  178. been added.
  179. * For PostGIS users, the new :class:`~django.contrib.gis.db.models.RasterField`
  180. allows :ref:`storing GDALRaster objects <creating-and-saving-raster-models>`.
  181. It supports automatic spatial index creation and reprojection when saving a
  182. model. It does not yet support spatial querying.
  183. * The new :meth:`GDALRaster.warp() <django.contrib.gis.gdal.GDALRaster.warp>`
  184. method allows warping a raster by specifying target raster properties such as
  185. origin, width, height, or pixel size (amongst others).
  186. * The new :meth:`GDALRaster.transform()
  187. <django.contrib.gis.gdal.GDALRaster.transform>` method allows transforming a
  188. raster into a different spatial reference system by specifying a target
  189. ``srid``.
  190. * The new :class:`~django.contrib.gis.geoip2.GeoIP2` class allows using
  191. MaxMind's GeoLite2 databases which includes support for IPv6 addresses.
  192. :mod:`django.contrib.postgres`
  193. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  194. * Added support for the :lookup:`rangefield.contained_by` lookup for some built
  195. in fields which correspond to the range fields.
  196. * Added :class:`~django.contrib.postgres.fields.JSONField`.
  197. * Added :doc:`/ref/contrib/postgres/aggregates`.
  198. * Fixed serialization of
  199. :class:`~django.contrib.postgres.fields.DateRangeField` and
  200. :class:`~django.contrib.postgres.fields.DateTimeRangeField`.
  201. * Added the :class:`~django.contrib.postgres.functions.TransactionNow` database
  202. function.
  203. :mod:`django.contrib.sessions`
  204. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  205. * The session model and ``SessionStore`` classes for the ``db`` and
  206. ``cached_db`` backends are refactored to allow a custom database session
  207. backend to build upon them. See
  208. :ref:`extending-database-backed-session-engines` for more details.
  209. :mod:`django.contrib.sites`
  210. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  211. * :func:`~django.contrib.sites.shortcuts.get_current_site` now handles the case
  212. where ``request.get_host()`` returns ``domain:port``, e.g.
  213. ``example.com:80``. If the lookup fails because the host does not match a
  214. record in the database and the host has a port, the port is stripped and the
  215. lookup is retried with the domain part only.
  216. :mod:`django.contrib.syndication`
  217. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  218. * Support for multiple enclosures per feed item has been added. If multiple
  219. enclosures are defined on a RSS feed, an exception is raised as RSS feeds,
  220. unlike Atom feeds, do not support multiple enclosures per feed item.
  221. Cache
  222. ^^^^^
  223. * ``django.core.cache.backends.base.BaseCache`` now has a ``get_or_set()``
  224. method.
  225. * :func:`django.views.decorators.cache.never_cache` now sends more persuasive
  226. headers (added ``no-cache, no-store, must-revalidate`` to ``Cache-Control``)
  227. to better prevent caching.
  228. CSRF
  229. ^^^^
  230. * The request header's name used for CSRF authentication can be customized
  231. with :setting:`CSRF_HEADER_NAME`.
  232. * The CSRF referer header is now validated against the
  233. :setting:`CSRF_COOKIE_DOMAIN` setting if set. See :ref:`how-csrf-works` for
  234. details.
  235. * The new :setting:`CSRF_TRUSTED_ORIGINS` setting provides a way to allow
  236. cross-origin unsafe requests (e.g. ``POST``) over HTTPS.
  237. Database backends
  238. ^^^^^^^^^^^^^^^^^
  239. * The PostgreSQL backend (``django.db.backends.postgresql_psycopg2``) is also
  240. available as ``django.db.backends.postgresql``. The old name will continue to
  241. be available for backwards compatibility.
  242. File Storage
  243. ^^^^^^^^^^^^
  244. * :meth:`Storage.get_valid_name()
  245. <django.core.files.storage.Storage.get_valid_name>` is now called when
  246. the :attr:`~django.db.models.FileField.upload_to` is a callable.
  247. * :class:`~django.core.files.File` now has the ``seekable()`` method when using
  248. Python 3.
  249. Forms
  250. ^^^^^
  251. * :class:`~django.forms.ModelForm` accepts the new ``Meta`` option
  252. ``field_classes`` to customize the type of the fields. See
  253. :ref:`modelforms-overriding-default-fields` for details.
  254. * You can now specify the order in which form fields are rendered with the
  255. :attr:`~django.forms.Form.field_order` attribute, the ``field_order``
  256. constructor argument , or the :meth:`~django.forms.Form.order_fields` method.
  257. * A form prefix can be specified inside a form class, not only when
  258. instantiating a form. See :ref:`form-prefix` for details.
  259. * You can now :ref:`specify keyword arguments <custom-formset-form-kwargs>`
  260. that you want to pass to the constructor of forms in a formset.
  261. * :class:`~django.forms.SlugField` now accepts an
  262. :attr:`~django.forms.SlugField.allow_unicode` argument to allow Unicode
  263. characters in slugs.
  264. * :class:`~django.forms.CharField` now accepts a
  265. :attr:`~django.forms.CharField.strip` argument to strip input data of leading
  266. and trailing whitespace. As this defaults to ``True`` this is different
  267. behavior from previous releases.
  268. * Form fields now support the :attr:`~django.forms.Field.disabled` argument,
  269. allowing the field widget to be displayed disabled by browsers.
  270. * It's now possible to customize bound fields by overriding a field's
  271. :meth:`~django.forms.Field.get_bound_field()` method.
  272. Generic Views
  273. ^^^^^^^^^^^^^
  274. * Class-based views generated using ``as_view()`` now have ``view_class``
  275. and ``view_initkwargs`` attributes.
  276. * :func:`~django.utils.decorators.method_decorator` can now be used with a list
  277. or tuple of decorators. It can also be used to :ref:`decorate classes instead
  278. of methods <decorating-class-based-views>`.
  279. Internationalization
  280. ^^^^^^^^^^^^^^^^^^^^
  281. * The :func:`django.views.i18n.set_language` view now properly redirects to
  282. :ref:`translated URLs <url-internationalization>`, when available.
  283. * The :func:`django.views.i18n.javascript_catalog` view now works correctly
  284. if used multiple times with different configurations on the same page.
  285. * The :func:`django.utils.timezone.make_aware` function gained an ``is_dst``
  286. argument to help resolve ambiguous times during DST transitions.
  287. * You can now use locale variants supported by gettext. These are usually used
  288. for languages which can be written in different scripts, for example Latin
  289. and Cyrillic (e.g. ``be@latin``).
  290. * Added the :func:`django.views.i18n.json_catalog` view to help build a custom
  291. client-side i18n library upon Django translations. It returns a JSON object
  292. containing a translations catalog, formatting settings, and a plural rule.
  293. * Added the ``name_translated`` attribute to the object returned by the
  294. :ttag:`get_language_info` template tag. Also added a corresponding template
  295. filter: :tfilter:`language_name_translated`.
  296. * You can now run :djadmin:`compilemessages` from the root directory of your
  297. project and it will find all the app message files that were created by
  298. :djadmin:`makemessages`.
  299. * :djadmin:`makemessages` now calls xgettext once per locale directory rather
  300. than once per translatable file. This speeds up localization builds.
  301. * :ttag:`blocktrans` supports assigning its output to a variable using
  302. ``asvar``.
  303. Management Commands
  304. ^^^^^^^^^^^^^^^^^^^
  305. * The new :djadmin:`sendtestemail` command lets you send a test email to
  306. easily confirm that email sending through Django is working.
  307. * To increase the readability of the SQL code generated by
  308. :djadmin:`sqlmigrate`, the SQL code generated for each migration operation is
  309. preceded by the operation's description.
  310. * The :djadmin:`dumpdata` command output is now deterministically ordered.
  311. Moreover, when the ``--ouput`` option is specified, it also shows a progress
  312. bar in the terminal.
  313. * The :djadmin:`createcachetable` command now has a ``--dry-run`` flag to
  314. print out the SQL rather than execute it.
  315. * The :djadmin:`startapp` command creates an ``apps.py`` file.
  316. * When using the PostgreSQL backend, the :djadmin:`dbshell` command can connect
  317. to the database using the password from your settings file (instead of
  318. requiring it to be manually entered).
  319. * The ``django`` package may be run as a script, i.e. ``python -m django``,
  320. which will behave the same as ``django-admin``.
  321. * Management commands that have the ``--noinput`` option now also take
  322. ``--no-input`` as an alias for that option.
  323. Migrations
  324. ^^^^^^^^^^
  325. * Initial migrations are now marked with an :attr:`initial = True
  326. <django.db.migrations.Migration.initial>` class attribute which allows
  327. :djadminopt:`migrate --fake-initial <--fake-initial>` to more easily detect
  328. initial migrations.
  329. * Added support for serialization of ``functools.partial`` objects.
  330. * When supplying ``None`` as a value in :setting:`MIGRATION_MODULES`, Django
  331. will consider the app an app without migrations.
  332. * When applying migrations, the "Rendering model states" step that's displayed
  333. when running migrate with verbosity 2 or higher now computes only the states
  334. for the migrations that have already been applied. The model states for
  335. migrations being applied are generated on demand, drastically reducing the
  336. amount of required memory.
  337. However, this improvement is not available when unapplying migrations and
  338. therefore still requires the precomputation and storage of the intermediate
  339. migration states.
  340. This improvement also requires that Django no longer supports mixed migration
  341. plans. Mixed plans consist of a list of migrations where some are being
  342. applied and others are being unapplied. This was never officially supported
  343. and never had a public API that supports this behavior.
  344. * The :djadmin:`squashmigrations` command now supports specifying the starting
  345. migration from which migrations will be squashed.
  346. Models
  347. ^^^^^^
  348. * :meth:`QuerySet.bulk_create() <django.db.models.query.QuerySet.bulk_create>`
  349. now works on proxy models.
  350. * Database configuration gained a :setting:`TIME_ZONE <DATABASE-TIME_ZONE>`
  351. option for interacting with databases that store datetimes in local time and
  352. don't support time zones when :setting:`USE_TZ` is ``True``.
  353. * Added the :meth:`RelatedManager.set()
  354. <django.db.models.fields.related.RelatedManager.set()>` method to the related
  355. managers created by ``ForeignKey``, ``GenericForeignKey``, and
  356. ``ManyToManyField``.
  357. * The :meth:`~django.db.models.fields.related.RelatedManager.add` method on
  358. a reverse foreign key now has a ``bulk`` parameter to allow executing one
  359. query regardless of the number of objects being added rather than one query
  360. per object.
  361. * Added the ``keep_parents`` parameter to :meth:`Model.delete()
  362. <django.db.models.Model.delete>` to allow deleting only a child's data in a
  363. model that uses multi-table inheritance.
  364. * :meth:`Model.delete() <django.db.models.Model.delete>`
  365. and :meth:`QuerySet.delete() <django.db.models.query.QuerySet.delete>` return
  366. the number of objects deleted.
  367. * Added a system check to prevent defining both ``Meta.ordering`` and
  368. ``order_with_respect_to`` on the same model.
  369. * :lookup:`Date and time <year>` lookups can be chained with other lookups
  370. (such as :lookup:`exact`, :lookup:`gt`, :lookup:`lt`, etc.). For example:
  371. ``Entry.objects.filter(pub_date__month__gt=6)``.
  372. * Time lookups (hour, minute, second) are now supported by
  373. :class:`~django.db.models.TimeField` for all database backends. Support for
  374. backends other than SQLite was added but undocumented in Django 1.7.
  375. * You can specify the ``output_field`` parameter of the
  376. :class:`~django.db.models.Avg` aggregate in order to aggregate over
  377. non-numeric columns, such as ``DurationField``.
  378. * Added the :lookup:`date` lookup to :class:`~django.db.models.DateTimeField`
  379. to allow querying the field by only the date portion.
  380. * Added the :class:`~django.db.models.functions.Greatest` and
  381. :class:`~django.db.models.functions.Least` database functions.
  382. * Added the :class:`~django.db.models.functions.Now` database function, which
  383. returns the current date and time.
  384. * :class:`~django.db.models.Transform` is now a subclass of
  385. :ref:`Func() <func-expressions>` which allows ``Transform``\s to be used on
  386. the right hand side of an expression, just like regular ``Func``\s. This
  387. allows registering some database functions like
  388. :class:`~django.db.models.functions.Length`,
  389. :class:`~django.db.models.functions.Lower`, and
  390. :class:`~django.db.models.functions.Upper` as transforms.
  391. * :class:`~django.db.models.SlugField` now accepts an
  392. :attr:`~django.db.models.SlugField.allow_unicode` argument to allow Unicode
  393. characters in slugs.
  394. * Added support for referencing annotations in ``QuerySet.distinct()``.
  395. * ``connection.queries`` shows queries with substituted parameters on SQLite.
  396. * Added a new model field check that makes sure
  397. :attr:`~django.db.models.Field.default` is a valid value.
  398. Requests and Responses
  399. ^^^^^^^^^^^^^^^^^^^^^^
  400. * Unless :attr:`HttpResponse.reason_phrase
  401. <django.http.HttpResponse.reason_phrase>` is explicitly set, it now is
  402. determined by the current value of :attr:`HttpResponse.status_code
  403. <django.http.HttpResponse.status_code>`. Modifying the value of
  404. ``status_code`` outside of the constructor will also modify the value of
  405. ``reason_phrase``.
  406. * The debug view now shows details of chained exceptions on Python 3.
  407. * The default 40x error views now accept a second positional parameter, the
  408. exception that triggered the view.
  409. * View error handlers now support
  410. :class:`~django.template.response.TemplateResponse`, commonly used with
  411. class-based views.
  412. * Exceptions raised by the ``render()`` method are now passed to the
  413. ``process_exception()`` method of each middleware.
  414. * Request middleware can now set :attr:`HttpRequest.urlconf
  415. <django.http.HttpRequest.urlconf>` to ``None`` to revert any changes made
  416. by previous middleware and return to using the :setting:`ROOT_URLCONF`.
  417. * The :setting:`DISALLOWED_USER_AGENTS` check in
  418. :class:`~django.middleware.common.CommonMiddleware` now raises a
  419. :class:`~django.core.exceptions.PermissionDenied` exception as opposed to
  420. returning an :class:`~django.http.HttpResponseForbidden` so that
  421. :data:`~django.conf.urls.handler403` is invoked.
  422. * Added :meth:`HttpRequest.get_port() <django.http.HttpRequest.get_port>` to
  423. fetch the originating port of the request.
  424. * Added the ``json_dumps_params`` parameter to
  425. :class:`~django.http.JsonResponse` to allow passing keyword arguments to the
  426. ``json.dumps()`` call used to generate the response.
  427. * The :class:`~django.middleware.common.BrokenLinkEmailsMiddleware` now
  428. ignores 404s when the referer is equal to the requested URL. To circumvent
  429. the empty referer check already implemented, some Web bots set the referer to
  430. the requested URL.
  431. Templates
  432. ^^^^^^^^^
  433. * Template tags created with the :meth:`~django.template.Library.simple_tag`
  434. helper can now store results in a template variable by using the ``as``
  435. argument.
  436. * Added a :meth:`Context.setdefault() <django.template.Context.setdefault>`
  437. method.
  438. * A warning will now be logged for missing context variables. These messages
  439. will be logged to the :ref:`django.template <django-template-logger>` logger.
  440. * The :ttag:`firstof` template tag supports storing the output in a variable
  441. using 'as'.
  442. * :meth:`Context.update() <django.template.Context.update>` can now be used as
  443. a context manager.
  444. * Django template loaders can now extend templates recursively.
  445. * The debug page template postmortem now include output from each engine that
  446. is installed.
  447. * :ref:`Debug page integration <template-debug-integration>` for custom
  448. template engines was added.
  449. * The :class:`~django.template.backends.django.DjangoTemplates` backend gained
  450. the ability to register libraries and builtins explicitly through the
  451. template :setting:`OPTIONS <TEMPLATES-OPTIONS>`.
  452. * The ``timesince`` and ``timeuntil`` filters were improved to deal with leap
  453. years when given large time spans.
  454. * The ``include`` tag now caches parsed templates objects during template
  455. rendering, speeding up reuse in places such as for loops.
  456. Tests
  457. ^^^^^
  458. * Added the :meth:`json() <django.test.Response.json>` method to test client
  459. responses to give access to the response body as JSON.
  460. * Added the :meth:`~django.test.Client.force_login()` method to the test
  461. client. Use this method to simulate the effect of a user logging into the
  462. site while skipping the authentication and verification steps of
  463. :meth:`~django.test.Client.login()`.
  464. URLs
  465. ^^^^
  466. * Regular expression lookaround assertions are now allowed in URL patterns.
  467. * The application namespace can now be set using an ``app_name`` attribute
  468. on the included module or object. It can also be set by passing a 2-tuple
  469. of (<list of patterns>, <application namespace>) as the first argument to
  470. :func:`~django.conf.urls.include`.
  471. Validators
  472. ^^^^^^^^^^
  473. * Added :func:`django.core.validators.int_list_validator` to generate
  474. validators of strings containing integers separated with a custom character.
  475. * :class:`~django.core.validators.EmailValidator` now limits the length of
  476. domain name labels to 63 characters per :rfc:`1034`.
  477. * Added :func:`~django.core.validators.validate_unicode_slug` to validate slugs
  478. that may contain Unicode characters.
  479. Backwards incompatible changes in 1.9
  480. =====================================
  481. .. warning::
  482. In addition to the changes outlined in this section, be sure to review the
  483. :ref:`removed-features-1.9` for the features that have reached the end of
  484. their deprecation cycle and therefore been removed. If you haven't updated
  485. your code within the deprecation timeline for a given feature, its removal
  486. may appear as a backwards incompatible change.
  487. Database backend API
  488. ~~~~~~~~~~~~~~~~~~~~
  489. * A couple of new tests rely on the ability of the backend to introspect column
  490. defaults (returning the result as ``Field.default``). You can set the
  491. ``can_introspect_default`` database feature to ``False`` if your backend
  492. doesn't implement this. You may want to review the implementation on the
  493. backends that Django includes for reference (:ticket:`24245`).
  494. * Registering a global adapter or converter at the level of the DB-API module
  495. to handle time zone information of :class:`~datetime.datetime` values passed
  496. as query parameters or returned as query results on databases that don't
  497. support time zones is discouraged. It can conflict with other libraries.
  498. The recommended way to add a time zone to :class:`~datetime.datetime` values
  499. fetched from the database is to register a converter for ``DateTimeField``
  500. in ``DatabaseOperations.get_db_converters()``.
  501. The ``needs_datetime_string_cast`` database feature was removed. Database
  502. backends that set it must register a converter instead, as explained above.
  503. * The ``DatabaseOperations.value_to_db_<type>()`` methods were renamed to
  504. ``adapt_<type>field_value()`` to mirror the ``convert_<type>field_value()``
  505. methods.
  506. * To use the new ``date`` lookup, third-party database backends may need to
  507. implement the ``DatabaseOperations.datetime_cast_date_sql()`` method.
  508. * The ``DatabaseOperations.time_extract_sql()`` method was added. It calls the
  509. existing ``date_extract_sql()`` method. This method is overridden by the
  510. SQLite backend to add time lookups (hour, minute, second) to
  511. :class:`~django.db.models.TimeField`, and may be needed by third-party
  512. database backends.
  513. * The ``DatabaseOperations.datetime_cast_sql()`` method (not to be confused
  514. with ``DatabaseOperations.datetime_cast_date_sql()`` mentioned above)
  515. has been removed. This method served to format dates on Oracle long
  516. before 1.0, but hasn't been overridden by any core backend in years
  517. and hasn't been called anywhere in Django's code or tests.
  518. * In order to support test parallelization, you must implement the
  519. ``DatabaseCreation._clone_test_db()`` method and set
  520. ``DatabaseFeatures.can_clone_databases = True``. You may have to adjust
  521. ``DatabaseCreation.get_test_db_clone_settings()``.
  522. Default settings that were tuples are now lists
  523. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  524. The default settings in ``django.conf.global_settings`` were a combination of
  525. lists and tuples. All settings that were formerly tuples are now lists.
  526. ``is_usable`` attribute on template loaders is removed
  527. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  528. Django template loaders previously required an ``is_usable`` attribute to be
  529. defined. If a loader was configured in the template settings and this attribute
  530. was ``False``, the loader would be silently ignored. In practice, this was only
  531. used by the egg loader to detect if setuptools was installed. The ``is_usable``
  532. attribute is now removed and the egg loader instead fails at runtime if
  533. setuptools is not installed.
  534. Related set direct assignment
  535. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  536. :ref:`Direct assignment <direct-assignment>` of related objects in the ORM used
  537. to perform a ``clear()`` followed by a call to ``add()``. This caused
  538. needlessly large data changes and prevented using the
  539. :data:`~django.db.models.signals.m2m_changed` signal to track individual
  540. changes in many-to-many relations.
  541. Direct assignment now relies on the the new
  542. :meth:`~django.db.models.fields.related.RelatedManager.set` method on related
  543. managers which by default only processes changes between the existing related
  544. set and the one that's newly assigned. The previous behavior can be restored by
  545. replacing direct assignment by a call to ``set()`` with the keyword argument
  546. ``clear=True``.
  547. ``ModelForm``, and therefore ``ModelAdmin``, internally rely on direct
  548. assignment for many-to-many relations and as a consequence now use the new
  549. behavior.
  550. Filesystem-based template loaders catch more specific exceptions
  551. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  552. When using the :class:`filesystem.Loader <django.template.loaders.filesystem.Loader>`
  553. or :class:`app_directories.Loader <django.template.loaders.app_directories.Loader>`
  554. template loaders, earlier versions of Django raised a
  555. :exc:`~django.template.TemplateDoesNotExist` error if a template source existed
  556. but was unreadable. This could happen under many circumstances, such as if
  557. Django didn't have permissions to open the file, or if the template source was
  558. a directory. Now, Django only silences the exception if the template source
  559. does not exist. All other situations result in the original ``IOError`` being
  560. raised.
  561. HTTP redirects no longer forced to absolute URIs
  562. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  563. Relative redirects are no longer converted to absolute URIs. :rfc:`2616`
  564. required the ``Location`` header in redirect responses to be an absolute URI,
  565. but it has been superseded by :rfc:`7231` which allows relative URIs in
  566. ``Location``, recognizing the actual practice of user agents, almost all of
  567. which support them.
  568. Consequently, the expected URLs passed to ``assertRedirects`` should generally
  569. no longer include the scheme and domain part of the URLs. For example,
  570. ``self.assertRedirects(response, 'http://testserver/some-url/')`` should be
  571. replaced by ``self.assertRedirects(response, '/some-url/')`` (unless the
  572. redirection specifically contained an absolute URL, of course).
  573. Dropped support for PostgreSQL 9.0
  574. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  575. Upstream support for PostgreSQL 9.0 ended in September 2015. As a consequence,
  576. Django 1.9 sets 9.1 as the minimum PostgreSQL version it officially supports.
  577. Dropped support for Oracle 11.1
  578. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  579. Upstream support for Oracle 11.1 ended in August 2015. As a consequence, Django
  580. 1.9 sets 11.2 as the minimum Oracle version it officially supports.
  581. Bulk behavior of ``add()`` method of related managers
  582. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  583. To improve performance, the ``add()`` methods of the related managers created
  584. by ``ForeignKey`` and ``GenericForeignKey`` changed from a series of
  585. ``Model.save()`` calls to a single ``QuerySet.update()`` call. The change means
  586. that ``pre_save`` and ``post_save`` signals aren't sent anymore. You can use
  587. the ``bulk=False`` keyword argument to revert to the previous behavior.
  588. Template ``LoaderOrigin`` and ``StringOrigin`` are removed
  589. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  590. In previous versions of Django, when a template engine was initialized with
  591. debug as ``True``, an instance of ``django.template.loader.LoaderOrigin`` or
  592. ``django.template.base.StringOrigin`` was set as the origin attribute on the
  593. template object. These classes have been combined into
  594. :class:`~django.template.base.Origin` and is now always set regardless of the
  595. engine debug setting.
  596. .. _default-logging-changes-19:
  597. Changes to the default logging configuration
  598. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  599. To make it easier to write custom logging configurations, Django's default
  600. logging configuration no longer defines 'django.request' and 'django.security'
  601. loggers. Instead, it defines a single 'django' logger with two handlers:
  602. * 'console': filtered at the ``INFO`` level and only active if ``DEBUG=True``.
  603. * 'mail_admins': filtered at the ``ERROR`` level and only active if
  604. ``DEBUG=False``.
  605. If you aren't overriding Django's default logging, you should see minimal
  606. changes in behavior, but you might see some new logging to the ``runserver``
  607. console, for example.
  608. If you are overriding Django's default logging, you should check to see how
  609. your configuration merges with the new defaults.
  610. ``HttpRequest`` details in error reporting
  611. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  612. It was redundant to display the full details of the
  613. :class:`~django.http.HttpRequest` each time it appeared as a stack frame
  614. variable in the HTML version of the debug page and error email. Thus, the HTTP
  615. request will now display the same standard representation as other variables
  616. (``repr(request)``). As a result, the method
  617. ``ExceptionReporterFilter.get_request_repr()`` was removed.
  618. The contents of the text version of the email were modified to provide a
  619. traceback of the same structure as in the case of AJAX requests. The traceback
  620. details are rendered by the ``ExceptionReporter.get_traceback_text()`` method.
  621. Removal of time zone aware global adapters and converters for datetimes
  622. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  623. Django no longer registers global adapters and converters for managing time
  624. zone information on :class:`~datetime.datetime` values sent to the database as
  625. query parameters or read from the database in query results. This change
  626. affects projects that meet all the following conditions:
  627. * The :setting:`USE_TZ` setting is ``True``.
  628. * The database is SQLite, MySQL, Oracle, or a third-party database that
  629. doesn't support time zones. In doubt, you can check the value of
  630. ``connection.features.supports_timezones``.
  631. * The code queries the database outside of the ORM, typically with
  632. ``cursor.execute(sql, params)``.
  633. If you're passing aware :class:`~datetime.datetime` parameters to such
  634. queries, you should turn them into naive datetimes in UTC::
  635. from django.utils import timezone
  636. param = timezone.make_naive(param, timezone.utc)
  637. If you fail to do so, the conversion will be performed as in earlier versions
  638. (with a deprecation warning) up until Django 1.11. Django 2.0 won't perform any
  639. conversion, which may result in data corruption.
  640. If you're reading :class:`~datetime.datetime` values from the results, they
  641. will be naive instead of aware. You can compensate as follows::
  642. from django.utils import timezone
  643. value = timezone.make_aware(value, timezone.utc)
  644. You don't need any of this if you're querying the database through the ORM,
  645. even if you're using :meth:`raw() <django.db.models.query.QuerySet.raw>`
  646. queries. The ORM takes care of managing time zone information.
  647. Template tag modules are imported when templates are configured
  648. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  649. The :class:`~django.template.backends.django.DjangoTemplates` backend now
  650. performs discovery on installed template tag modules when instantiated. This
  651. update enables libraries to be provided explicitly via the ``'libraries'``
  652. key of :setting:`OPTIONS <TEMPLATES-OPTIONS>` when defining a
  653. :class:`~django.template.backends.django.DjangoTemplates` backend. Import
  654. or syntax errors in template tag modules now fail early at instantiation time
  655. rather than when a template with a :ttag:`{% load %}<load>` tag is first
  656. compiled.
  657. ``django.template.base.add_to_builtins()`` is removed
  658. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  659. Although it was a private API, projects commonly used ``add_to_builtins()`` to
  660. make template tags and filters available without using the
  661. :ttag:`{% load %}<load>` tag. This API has been formalized. Projects should now
  662. define built-in libraries via the ``'builtins'`` key of :setting:`OPTIONS
  663. <TEMPLATES-OPTIONS>` when defining a
  664. :class:`~django.template.backends.django.DjangoTemplates` backend.
  665. .. _simple-tag-conditional-escape-fix:
  666. ``simple_tag`` now wraps tag output in ``conditional_escape``
  667. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  668. In general, template tags do not autoescape their contents, and this behavior is
  669. :ref:`documented <tags-auto-escaping>`. For tags like
  670. :class:`~django.template.Library.inclusion_tag`, this is not a problem because
  671. the included template will perform autoescaping. For
  672. :class:`~django.template.Library.assignment_tag`, the output will be escaped
  673. when it is used as a variable in the template.
  674. For the intended use cases of :class:`~django.template.Library.simple_tag`,
  675. however, it is very easy to end up with incorrect HTML and possibly an XSS
  676. exploit. For example::
  677. @register.simple_tag(takes_context=True)
  678. def greeting(context):
  679. return "Hello {0}!".format(context['request'].user.first_name)
  680. In older versions of Django, this will be an XSS issue because
  681. ``user.first_name`` is not escaped.
  682. In Django 1.9, this is fixed: if the template context has ``autoescape=True``
  683. set (the default), then ``simple_tag`` will wrap the output of the tag function
  684. with :func:`~django.utils.html.conditional_escape`.
  685. To fix your ``simple_tag``\s, it is best to apply the following practices:
  686. * Any code that generates HTML should use either the template system or
  687. :func:`~django.utils.html.format_html`.
  688. * If the output of a ``simple_tag`` needs escaping, use
  689. :func:`~django.utils.html.escape` or
  690. :func:`~django.utils.html.conditional_escape`.
  691. * If you are absolutely certain that you are outputting HTML from a trusted
  692. source (e.g. a CMS field that stores HTML entered by admins), you can mark it
  693. as such using :func:`~django.utils.safestring.mark_safe`.
  694. Tags that follow these rules will be correct and safe whether they are run on
  695. Django 1.9+ or earlier.
  696. ``Paginator.page_range``
  697. ~~~~~~~~~~~~~~~~~~~~~~~~
  698. :attr:`Paginator.page_range <django.core.paginator.Paginator.page_range>` is
  699. now an iterator instead of a list.
  700. In versions of Django previous to 1.8, ``Paginator.page_range`` returned a
  701. ``list`` in Python 2 and a ``range`` in Python 3. Django 1.8 consistently
  702. returned a list, but an iterator is more efficient.
  703. Existing code that depends on ``list`` specific features, such as indexing,
  704. can be ported by converting the iterator into a ``list`` using ``list()``.
  705. Implicit ``QuerySet`` ``__in`` lookup removed
  706. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  707. In earlier versions, queries such as::
  708. Model.objects.filter(related_id=RelatedModel.objects.all())
  709. would implicitly convert to::
  710. Model.objects.filter(related_id__in=RelatedModel.objects.all())
  711. resulting in SQL like ``"related_id IN (SELECT id FROM ...)"``.
  712. This implicit ``__in`` no longer happens so the "IN" SQL is now "=", and if the
  713. subquery returns multiple results, at least some databases will throw an error.
  714. .. _admin-browser-support-19:
  715. ``contrib.admin`` browser support
  716. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  717. The admin no longer supports Internet Explorer 8 and below, as these browsers
  718. have reached end-of-life.
  719. CSS and images to support Internet Explorer 6 and 7 have been removed. PNG and
  720. GIF icons have been replaced with SVG icons, which are not supported by
  721. Internet Explorer 8 and earlier.
  722. The jQuery library embedded in the admin has been upgraded from version 1.11.2
  723. to 2.1.4. jQuery 2.x has the same API as jQuery 1.x, but does not support
  724. Internet Explorer 6, 7, or 8, allowing for better performance and a smaller
  725. file size. If you need to support IE8 and must also use the latest version of
  726. Django, you can override the admin's copy of jQuery with your own by creating
  727. a Django application with this structure::
  728. app/static/admin/js/vendor/
  729. jquery.js
  730. jquery.min.js
  731. Miscellaneous
  732. ~~~~~~~~~~~~~
  733. * The jQuery static files in ``contrib.admin`` have been moved into a
  734. ``vendor/jquery`` subdirectory.
  735. * The text displayed for null columns in the admin changelist ``list_display``
  736. cells has changed from ``(None)`` (or its translated equivalent) to ``-`` (a
  737. dash).
  738. * ``django.http.responses.REASON_PHRASES`` and
  739. ``django.core.handlers.wsgi.STATUS_CODE_TEXT`` have been removed. Use
  740. Python's stdlib instead: :data:`http.client.responses` for Python 3 and
  741. `httplib.responses`_ for Python 2.
  742. .. _`httplib.responses`: https://docs.python.org/2/library/httplib.html#httplib.responses
  743. * ``ValuesQuerySet`` and ``ValuesListQuerySet`` have been removed.
  744. * The ``admin/base.html`` template no longer sets
  745. ``window.__admin_media_prefix__`` or ``window.__admin_utc_offset__``. Image
  746. references in JavaScript that used that value to construct absolute URLs have
  747. been moved to CSS for easier customization. The UTC offset is stored on a
  748. data attribute of the ``<body>`` tag.
  749. * ``CommaSeparatedIntegerField`` validation has been refined to forbid values
  750. like ``','``, ``',1'``, and ``'1,,2'``.
  751. * Form initialization was moved from the :meth:`ProcessFormView.get()
  752. <django.views.generic.edit.ProcessFormView.get>` method to the new
  753. :meth:`FormMixin.get_context_data()
  754. <django.views.generic.edit.FormMixin.get_context_data>` method. This may be
  755. backwards incompatible if you have overridden the ``get_context_data()``
  756. method without calling ``super()``.
  757. * Support for PostGIS 1.5 has been dropped.
  758. * The ``django.contrib.sites.models.Site.domain`` field was changed to be
  759. :attr:`~django.db.models.Field.unique`.
  760. * In order to enforce test isolation, database queries are not allowed
  761. by default in :class:`~django.test.SimpleTestCase` tests anymore. You
  762. can disable this behavior by setting the
  763. :attr:`~django.test.SimpleTestCase.allow_database_queries` class attribute
  764. to ``True`` on your test class.
  765. * :attr:`ResolverMatch.app_name
  766. <django.core.urlresolvers.ResolverMatch.app_name>` was changed to contain
  767. the full namespace path in the case of nested namespaces. For consistency
  768. with :attr:`ResolverMatch.namespace
  769. <django.core.urlresolvers.ResolverMatch.namespace>`, the empty value is now
  770. an empty string instead of ``None``.
  771. * For security hardening, session keys must be at least 8 characters.
  772. * Private function ``django.utils.functional.total_ordering()`` has been
  773. removed. It contained a workaround for a ``functools.total_ordering()`` bug
  774. in Python versions older than 2.7.3.
  775. * XML serialization (either through :djadmin:`dumpdata` or the syndication
  776. framework) used to output any characters it received. Now if the content to
  777. be serialized contains any control characters not allowed in the XML 1.0
  778. standard, the serialization will fail with a :exc:`ValueError`.
  779. * :class:`~django.forms.CharField` now strips input of leading and trailing
  780. whitespace by default. This can be disabled by setting the new
  781. :attr:`~django.forms.CharField.strip` argument to ``False``.
  782. * Template text that is translated and uses two or more consecutive percent
  783. signs, e.g. ``"%%"``, may have a new `msgid` after ``makemessages`` is run
  784. (most likely the translation will be marked fuzzy). The new ``msgid`` will be
  785. marked ``"#, python-format"``.
  786. * If neither :attr:`request.current_app <django.http.HttpRequest.current_app>`
  787. nor :class:`Context.current_app <django.template.Context>` are set, the
  788. :ttag:`url` template tag will now use the namespace of the current request.
  789. Set ``request.current_app`` to ``None`` if you don't want to use a namespace
  790. hint.
  791. * The :setting:`SILENCED_SYSTEM_CHECKS` setting now silences messages of all
  792. levels. Previously, messages of ``ERROR`` level or higher were printed to the
  793. console.
  794. * The ``FlatPage.enable_comments`` field is removed from the ``FlatPageAdmin``
  795. as it's unused by the application. If your project or a third-party app makes
  796. use of it, :ref:`create a custom ModelAdmin <flatpages-admin>` to add it back.
  797. * The return value of
  798. :meth:`~django.test.runner.DiscoverRunner.setup_databases` and the first
  799. argument of :meth:`~django.test.runner.DiscoverRunner.teardown_databases`
  800. changed. They used to be ``(old_names, mirrors)`` tuples. Now they're just
  801. the first item, ``old_names``.
  802. * By default :class:`~django.test.LiveServerTestCase` attempts to find an
  803. available port in the 8081-8179 range instead of just trying port 8081.
  804. * The system checks for :class:`~django.contrib.admin.ModelAdmin` now check
  805. instances rather than classes.
  806. * The private API to apply mixed migration plans has been dropped for
  807. performance reasons. Mixed plans consist of a list of migrations where some
  808. are being applied and others are being unapplied.
  809. .. _deprecated-features-1.9:
  810. Features deprecated in 1.9
  811. ==========================
  812. ``assignment_tag()``
  813. ~~~~~~~~~~~~~~~~~~~~
  814. Django 1.4 added the ``assignment_tag`` helper to ease the creation of
  815. template tags that store results in a template variable. The
  816. :meth:`~django.template.Library.simple_tag` helper has gained this same
  817. ability, making the ``assignment_tag`` obsolete. Tags that use
  818. ``assignment_tag`` should be updated to use ``simple_tag``.
  819. ``{% cycle %}`` syntax with comma-separated arguments
  820. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  821. The :ttag:`cycle` tag supports an inferior old syntax from previous Django
  822. versions:
  823. .. code-block:: html+django
  824. {% cycle row1,row2,row3 %}
  825. Its parsing caused bugs with the current syntax, so support for the old syntax
  826. will be removed in Django 1.10 following an accelerated deprecation.
  827. ``ForeignKey`` and ``OneToOneField`` ``on_delete`` argument
  828. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  829. In order to increase awareness about cascading model deletion, the
  830. ``on_delete`` argument of ``ForeignKey`` and ``OneToOneField`` will be required
  831. in Django 2.0.
  832. Update models and existing migrations to explicitly set the argument. Since the
  833. default is ``models.CASCADE``, add ``on_delete=models.CASCADE`` to all
  834. ``ForeignKey`` and ``OneToOneField``\s that don't use a different option. You
  835. can also pass it as the second positional argument if you don't care about
  836. compatibility with older versions of Django.
  837. ``Field.rel`` changes
  838. ~~~~~~~~~~~~~~~~~~~~~
  839. ``Field.rel`` and its methods and attributes have changed to match the related
  840. fields API. The ``Field.rel`` attribute is renamed to ``remote_field`` and many
  841. of its methods and attributes are either changed or renamed.
  842. The aim of these changes is to provide a documented API for relation fields.
  843. ``GeoManager`` and ``GeoQuerySet`` custom methods
  844. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  845. All custom ``GeoQuerySet`` methods (``area()``, ``distance()``, ``gml()``, ...)
  846. have been replaced by equivalent geographic expressions in annotations (see in
  847. new features). Hence the need to set a custom ``GeoManager`` to GIS-enabled
  848. models is now obsolete. As soon as your code doesn't call any of the deprecated
  849. methods, you can simply remove the ``objects = GeoManager()`` lines from your
  850. models.
  851. Template loader APIs have changed
  852. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  853. Django template loaders have been updated to allow recursive template
  854. extending. This change necessitated a new template loader API. The old
  855. ``load_template()`` and ``load_template_sources()`` methods are now deprecated.
  856. Details about the new API can be found :ref:`in the template loader
  857. documentation <custom-template-loaders>`.
  858. Passing a 3-tuple or an ``app_name`` to :func:`~django.conf.urls.include()`
  859. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  860. The instance namespace part of passing a tuple as the first argument has been
  861. replaced by passing the ``namespace`` argument to ``include()``. The
  862. ``app_name`` argument to ``include()`` has been replaced by passing a 2-tuple,
  863. or passing an object or module with an ``app_name`` attribute.
  864. If the ``app_name`` is set in this new way, the ``namespace`` argument is no
  865. longer required. It will default to the value of ``app_name``.
  866. This change also means that the old way of including an ``AdminSite`` instance
  867. is deprecated. Instead, pass ``admin.site.urls`` directly to
  868. :func:`~django.conf.urls.url()`:
  869. .. snippet::
  870. :filename: urls.py
  871. from django.conf.urls import url
  872. from django.contrib import admin
  873. urlpatterns = [
  874. url(r'^admin/', admin.site.urls),
  875. ]
  876. URL application namespace required if setting an instance namespace
  877. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  878. In the past, an instance namespace without an application namespace
  879. would serve the same purpose as the application namespace, but it was
  880. impossible to reverse the patterns if there was an application namespace
  881. with the same name. Includes that specify an instance namespace require that
  882. the included URLconf sets an application namespace.
  883. ``current_app`` parameter to ``contrib.auth`` views
  884. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  885. All views in ``django.contrib.auth.views`` have the following structure::
  886. def view(request, ..., current_app=None, ...):
  887. ...
  888. if current_app is not None:
  889. request.current_app = current_app
  890. return TemplateResponse(request, template_name, context)
  891. As of Django 1.8, ``current_app`` is set on the ``request`` object. For
  892. consistency, these views will require the caller to set ``current_app`` on the
  893. ``request`` instead of passing it in a separate argument.
  894. ``django.contrib.gis.geoip``
  895. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  896. The :mod:`django.contrib.gis.geoip2` module supersedes
  897. ``django.contrib.gis.geoip``. The new module provides a similar API except that
  898. it doesn't provide the legacy GeoIP-Python API compatibility methods.
  899. Miscellaneous
  900. ~~~~~~~~~~~~~
  901. * The ``weak`` argument to ``django.dispatch.signals.Signal.disconnect()`` has
  902. been deprecated as it has no effect.
  903. * The ``check_aggregate_support()`` method of
  904. ``django.db.backends.base.BaseDatabaseOperations`` has been deprecated and
  905. will be removed in Django 2.0. The more general ``check_expression_support()``
  906. should be used instead.
  907. * ``django.forms.extras`` is deprecated. You can find
  908. :class:`~django.forms.SelectDateWidget` in ``django.forms.widgets``
  909. (or simply ``django.forms``) instead.
  910. * Private API ``django.db.models.fields.add_lazy_relation()`` is deprecated.
  911. * The ``django.contrib.auth.tests.utils.skipIfCustomUser()`` decorator is
  912. deprecated. With the test discovery changes in Django 1.6, the tests for
  913. ``django.contrib`` apps are no longer run as part of the user's project.
  914. Therefore, the ``@skipIfCustomUser`` decorator is no longer needed to
  915. decorate tests in ``django.contrib.auth``.
  916. * If you customized some :ref:`error handlers <error-views>`, the view
  917. signatures with only one request parameter are deprecated. The views should
  918. now also accept a second ``exception`` positional parameter.
  919. * The ``django.utils.feedgenerator.Atom1Feed.mime_type`` and
  920. ``django.utils.feedgenerator.RssFeed.mime_type`` attributes are deprecated in
  921. favor of ``content_type``.
  922. * :class:`~django.core.signing.Signer` now issues a warning if an invalid
  923. separator is used. This will become an exception in Django 1.10.
  924. * ``django.db.models.Field._get_val_from_obj()`` is deprecated in favor of
  925. ``Field.value_from_object()``.
  926. * ``django.template.loaders.eggs.Loader`` is deprecated as distributing
  927. applications as eggs is not recommended.
  928. * The ``callable_obj`` keyword argument to
  929. ``SimpleTestCase.assertRaisesMessage()`` is deprecated. Pass the callable as
  930. a positional argument instead.
  931. * The ``allow_tags`` attribute on methods of ``ModelAdmin`` has been
  932. deprecated. Use :func:`~django.utils.html.format_html`,
  933. :func:`~django.utils.html.format_html_join`, or
  934. :func:`~django.utils.safestring.mark_safe` when constructing the method's
  935. return value instead.
  936. * The ``enclosure`` keyword argument to ``SyndicationFeed.add_item()`` is
  937. deprecated. Use the new ``enclosures`` argument which accepts a list of
  938. ``Enclosure`` objects instead of a single one.
  939. .. _removed-features-1.9:
  940. Features removed in 1.9
  941. =======================
  942. These features have reached the end of their deprecation cycle and so have been
  943. removed in Django 1.9 (please see the :ref:`deprecation timeline
  944. <deprecation-removed-in-1.9>` for more details):
  945. * ``django.utils.dictconfig`` is removed.
  946. * ``django.utils.importlib`` is removed.
  947. * ``django.utils.tzinfo`` is removed.
  948. * ``django.utils.unittest`` is removed.
  949. * The ``syncdb`` command is removed.
  950. * ``django.db.models.signals.pre_syncdb`` and
  951. ``django.db.models.signals.post_syncdb`` is removed.
  952. * Support for ``allow_syncdb`` on database routers is removed.
  953. * Automatic syncing of apps without migrations is removed. Migrations are
  954. compulsory for all apps unless you pass the :djadminopt:`--run-syncdb`
  955. option to ``migrate``.
  956. * Support for automatic loading of ``initial_data`` fixtures and initial SQL
  957. data is removed.
  958. * All models need to be defined inside an installed application or declare an
  959. explicit :attr:`~django.db.models.Options.app_label`. Furthermore, it isn't
  960. possible to import them before their application is loaded. In particular, it
  961. isn't possible to import models inside the root package of an application.
  962. * The model and form ``IPAddressField`` is removed. A stub field remains for
  963. compatibility with historical migrations.
  964. * ``AppCommand.handle_app()`` is no longer be supported.
  965. * ``RequestSite`` and ``get_current_site()`` are no longer importable from
  966. ``django.contrib.sites.models``.
  967. * FastCGI support via the ``runfcgi`` management command is removed.
  968. * ``django.utils.datastructures.SortedDict`` is removed.
  969. * ``ModelAdmin.declared_fieldsets`` is removed.
  970. * The ``util`` modules that provided backwards compatibility are removed:
  971. * ``django.contrib.admin.util``
  972. * ``django.contrib.gis.db.backends.util``
  973. * ``django.db.backends.util``
  974. * ``django.forms.util``
  975. * ``ModelAdmin.get_formsets`` is removed.
  976. * The backward compatible shims introduced to rename the
  977. ``BaseMemcachedCache._get_memcache_timeout()`` method to
  978. ``get_backend_timeout()`` is removed.
  979. * The ``--natural`` and ``-n`` options for :djadmin:`dumpdata` are removed.
  980. * The ``use_natural_keys`` argument for ``serializers.serialize()`` is removed.
  981. * Private API ``django.forms.forms.get_declared_fields()`` is removed.
  982. * The ability to use a ``SplitDateTimeWidget`` with ``DateTimeField`` is
  983. removed.
  984. * The ``WSGIRequest.REQUEST`` property is removed.
  985. * The class ``django.utils.datastructures.MergeDict`` is removed.
  986. * The ``zh-cn`` and ``zh-tw`` language codes are removed.
  987. * The internal ``django.utils.functional.memoize()`` is removed.
  988. * ``django.core.cache.get_cache`` is removed.
  989. * ``django.db.models.loading`` is removed.
  990. * Passing callable arguments to querysets is no longer possible.
  991. * ``BaseCommand.requires_model_validation`` is removed in favor of
  992. ``requires_system_checks``. Admin validators is replaced by admin checks.
  993. * The ``ModelAdmin.validator_class`` and ``default_validator_class`` attributes
  994. are removed.
  995. * ``ModelAdmin.validate()`` is removed.
  996. * ``django.db.backends.DatabaseValidation.validate_field`` is removed in
  997. favor of the ``check_field`` method.
  998. * The ``validate`` management command is removed.
  999. * ``django.utils.module_loading.import_by_path`` is removed in favor of
  1000. ``django.utils.module_loading.import_string``.
  1001. * ``ssi`` and ``url`` template tags are removed from the ``future`` template
  1002. tag library.
  1003. * ``django.utils.text.javascript_quote()`` is removed.
  1004. * Database test settings as independent entries in the database settings,
  1005. prefixed by ``TEST_``, are no longer supported.
  1006. * The `cache_choices` option to :class:`~django.forms.ModelChoiceField` and
  1007. :class:`~django.forms.ModelMultipleChoiceField` is removed.
  1008. * The default value of the
  1009. :attr:`RedirectView.permanent <django.views.generic.base.RedirectView.permanent>`
  1010. attribute has changed from ``True`` to ``False``.
  1011. * ``django.contrib.sitemaps.FlatPageSitemap`` is removed in favor of
  1012. ``django.contrib.flatpages.sitemaps.FlatPageSitemap``.
  1013. * Private API ``django.test.utils.TestTemplateLoader`` is removed.
  1014. * The ``django.contrib.contenttypes.generic`` module is removed.