1.9.txt 51 KB

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