1.9.txt 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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. Minor features
  93. ~~~~~~~~~~~~~~
  94. :mod:`django.contrib.admin`
  95. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  96. * Admin views now have ``model_admin`` or ``admin_site`` attributes.
  97. * The URL of the admin change view has been changed (was at
  98. ``/admin/<app>/<model>/<pk>/`` by default and is now at
  99. ``/admin/<app>/<model>/<pk>/change/``). This should not affect your
  100. application unless you have hardcoded admin URLs. In that case, replace those
  101. links by :ref:`reversing admin URLs <admin-reverse-urls>` instead. Note that
  102. the old URL still redirects to the new one for backwards compatibility, but
  103. it may be removed in a future version.
  104. * :meth:`ModelAdmin.get_list_select_related()
  105. <django.contrib.admin.ModelAdmin.get_list_select_related>` was added to allow
  106. changing the ``select_related()`` values used in the admin's changelist query
  107. based on the request.
  108. * The ``available_apps`` context variable, which lists the available
  109. applications for the current user, has been added to the
  110. :meth:`AdminSite.each_context() <django.contrib.admin.AdminSite.each_context>`
  111. method.
  112. * :attr:`AdminSite.empty_value_display
  113. <django.contrib.admin.AdminSite.empty_value_display>` and
  114. :attr:`ModelAdmin.empty_value_display
  115. <django.contrib.admin.ModelAdmin.empty_value_display>` were added to override
  116. the display of empty values in admin change list. You can also customize the
  117. value for each field.
  118. * The time picker widget includes a '6 p.m' option for consistency of having
  119. predefined options every 6 hours.
  120. :mod:`django.contrib.auth`
  121. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  122. * The default iteration count for the PBKDF2 password hasher has been increased
  123. by 20%. This backwards compatible change will not affect users who have
  124. subclassed ``django.contrib.auth.hashers.PBKDF2PasswordHasher`` to change the
  125. default value.
  126. * The ``BCryptSHA256PasswordHasher`` will now update passwords if its
  127. ``rounds`` attribute is changed.
  128. * ``AbstractBaseUser`` and ``BaseUserManager`` were moved to a new
  129. ``django.contrib.auth.base_user`` module so that they can be imported without
  130. including ``django.contrib.auth`` in :setting:`INSTALLED_APPS` (this raised
  131. a deprecation warning in older versions and is no longer supported in
  132. Django 1.9).
  133. * The permission argument of
  134. :func:`~django.contrib.auth.decorators.permission_required()` accepts all
  135. kinds of iterables, not only list and tuples.
  136. :mod:`django.contrib.gis`
  137. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  138. * All ``GeoQuerySet`` methods have been deprecated and replaced by
  139. :doc:`equivalent database functions </ref/contrib/gis/functions>`. As soon
  140. as the legacy methods have been replaced in your code, you should even be
  141. able to remove the special ``GeoManager`` from your GIS-enabled classes.
  142. * The GDAL interface now supports instantiating file-based and in-memory
  143. :ref:`GDALRaster objects <raster-data-source-objects>` from raw data.
  144. Setters for raster properties such as projection or pixel values have
  145. been added.
  146. * For PostGIS users, the new :class:`~django.contrib.gis.db.models.RasterField`
  147. allows :ref:`storing GDALRaster objects <creating-and-saving-raster-models>`.
  148. It supports automatic spatial index creation and reprojection when saving a
  149. model. It does not yet support spatial querying.
  150. * The new :meth:`GDALRaster.warp() <django.contrib.gis.gdal.GDALRaster.warp>`
  151. method allows warping a raster by specifying target raster properties such as
  152. origin, width, height, or pixel size (amongst others).
  153. * The new :meth:`GDALRaster.transform()
  154. <django.contrib.gis.gdal.GDALRaster.transform>` method allows transforming a
  155. raster into a different spatial reference system by specifying a target
  156. ``srid``.
  157. :mod:`django.contrib.messages`
  158. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  159. * ...
  160. :mod:`django.contrib.postgres`
  161. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  162. * Added support for the :lookup:`rangefield.contained_by` lookup for some built
  163. in fields which correspond to the range fields.
  164. * Added :class:`~django.contrib.postgres.fields.JSONField`.
  165. * Added :doc:`/ref/contrib/postgres/aggregates`.
  166. * Fixed serialization of
  167. :class:`~django.contrib.postgres.fields.DateRangeField` and
  168. :class:`~django.contrib.postgres.fields.DateTimeRangeField`.
  169. * Added the :class:`~django.contrib.postgres.functions.TransactionNow` database
  170. function.
  171. :mod:`django.contrib.redirects`
  172. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  173. * ...
  174. :mod:`django.contrib.sessions`
  175. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  176. * ...
  177. :mod:`django.contrib.sitemaps`
  178. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  179. * ...
  180. :mod:`django.contrib.sites`
  181. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  182. * :func:`~django.contrib.sites.shortcuts.get_current_site` now handles the case
  183. where ``request.get_host()`` returns ``domain:port``, e.g.
  184. ``example.com:80``. If the lookup fails because the host does not match a
  185. record in the database and the host has a port, the port is stripped and the
  186. lookup is retried with the domain part only.
  187. :mod:`django.contrib.staticfiles`
  188. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  189. * ...
  190. :mod:`django.contrib.syndication`
  191. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  192. * ...
  193. Cache
  194. ^^^^^
  195. * ``django.core.cache.backends.base.BaseCache`` now has a ``get_or_set()``
  196. method.
  197. * :func:`django.views.decorators.cache.never_cache` now sends more persuasive
  198. headers (added ``no-cache, no-store, must-revalidate`` to ``Cache-Control``)
  199. to better prevent caching.
  200. Email
  201. ^^^^^
  202. * ...
  203. File Storage
  204. ^^^^^^^^^^^^
  205. * :meth:`Storage.get_valid_name()
  206. <django.core.files.storage.Storage.get_valid_name>` is now called when
  207. the :attr:`~django.db.models.FileField.upload_to` is a callable.
  208. * :class:`~django.core.files.File` now has the ``seekable()`` method when using
  209. Python 3.
  210. File Uploads
  211. ^^^^^^^^^^^^
  212. * ...
  213. Forms
  214. ^^^^^
  215. * :class:`~django.forms.ModelForm` accepts the new ``Meta`` option
  216. ``field_classes`` to customize the type of the fields. See
  217. :ref:`modelforms-overriding-default-fields` for details.
  218. * You can now specify the order in which form fields are rendered with the
  219. :attr:`~django.forms.Form.field_order` attribute, the ``field_order``
  220. constructor argument , or the :meth:`~django.forms.Form.order_fields` method.
  221. * A form prefix can be specified inside a form class, not only when
  222. instantiating a form. See :ref:`form-prefix` for details.
  223. * You can now :ref:`specify keyword arguments <custom-formset-form-kwargs>`
  224. that you want to pass to the constructor of forms in a formset.
  225. Generic Views
  226. ^^^^^^^^^^^^^
  227. * Class based views generated using ``as_view()`` now have ``view_class``
  228. and ``view_initkwargs`` attributes.
  229. Internationalization
  230. ^^^^^^^^^^^^^^^^^^^^
  231. * The :func:`django.views.i18n.set_language` view now properly redirects to
  232. :ref:`translated URLs <url-internationalization>`, when available.
  233. * The :func:`django.views.i18n.javascript_catalog` view now works correctly
  234. if used multiple times with different configurations on the same page.
  235. * The :func:`django.utils.timezone.make_aware` function gained an ``is_dst``
  236. argument to help resolve ambiguous times during DST transitions.
  237. * You can now use locale variants supported by gettext. These are usually used
  238. for languages which can be written in different scripts, for example Latin
  239. and Cyrillic (e.g. ``be@latin``).
  240. * Added the ``name_translated`` attribute to the object returned by the
  241. :ttag:`get_language_info` template tag. Also added a corresponding template
  242. filter: :tfilter:`language_name_translated`.
  243. * You can now run :djadmin:`compilemessages` from the root directory of your
  244. project and it will find all the app message files that were created by
  245. :djadmin:`makemessages`.
  246. Management Commands
  247. ^^^^^^^^^^^^^^^^^^^
  248. * The new :djadmin:`sendtestemail` command lets you send a test email to
  249. easily confirm that email sending through Django is working.
  250. * To increase the readability of the SQL code generated by
  251. :djadmin:`sqlmigrate`, the SQL code generated for each migration operation is
  252. preceded by the operation's description.
  253. * The :djadmin:`dumpdata` command output is now deterministically ordered.
  254. * The :djadmin:`createcachetable` command now has a ``--dry-run`` flag to
  255. print out the SQL rather than execute it.
  256. * The :djadmin:`startapp` command creates an ``apps.py`` file and adds
  257. ``default_app_config`` in ``__init__.py``.
  258. Models
  259. ^^^^^^
  260. * Database configuration gained a :setting:`TIME_ZONE <DATABASE-TIME_ZONE>`
  261. option for interacting with databases that store datetimes in local time and
  262. don't support time zones when :setting:`USE_TZ` is ``True``.
  263. * Added the :meth:`RelatedManager.set()
  264. <django.db.models.fields.related.RelatedManager.set()>` method to the related
  265. managers created by ``ForeignKey``, ``GenericForeignKey``, and
  266. ``ManyToManyField``.
  267. * Added the ``keep_parents`` parameter to :meth:`Model.delete()
  268. <django.db.models.Model.delete>` to allow deleting only a child's data in a
  269. model that uses multi-table inheritance.
  270. * :meth:`Model.delete() <django.db.models.Model.delete>`
  271. and :meth:`QuerySet.delete() <django.db.models.query.QuerySet.delete>` return
  272. the number of objects deleted.
  273. * Added a system check to prevent defining both ``Meta.ordering`` and
  274. ``order_with_respect_to`` on the same model.
  275. * :lookup:`Date and time <year>` lookups can be chained with other lookups
  276. (such as :lookup:`exact`, :lookup:`gt`, :lookup:`lt`, etc.). For example:
  277. ``Entry.objects.filter(pub_date__month__gt=6)``.
  278. * Time lookups (hour, minute, second) are now supported by
  279. :class:`~django.db.models.TimeField` for all database backends. Support for
  280. backends other than SQLite was added but undocumented in Django 1.7.
  281. * You can specify the ``output_field`` parameter of the
  282. :class:`~django.db.models.Avg` aggregate in order to aggregate over
  283. non-numeric columns, such as ``DurationField``.
  284. * Added the :lookup:`date` lookup to :class:`~django.db.models.DateTimeField`
  285. to allow querying the field by only the date portion.
  286. * Added the :class:`~django.db.models.functions.Greatest` and
  287. :class:`~django.db.models.functions.Least` database functions.
  288. * Added the :class:`~django.db.models.functions.Now` database function, which
  289. returns the current date and time.
  290. CSRF
  291. ^^^^
  292. * The request header's name used for CSRF authentication can be customized
  293. with :setting:`CSRF_HEADER_NAME`.
  294. Signals
  295. ^^^^^^^
  296. * ...
  297. Templates
  298. ^^^^^^^^^
  299. * Template tags created with the :meth:`~django.template.Library.simple_tag`
  300. helper can now store results in a template variable by using the ``as``
  301. argument.
  302. * Added a :meth:`Context.setdefault() <django.template.Context.setdefault>`
  303. method.
  304. * A warning will now be logged for missing context variables. These messages
  305. will be logged to the :ref:`django.template <django-template-logger>` logger.
  306. * The :ttag:`firstof` template tag supports storing the output in a variable
  307. using 'as'.
  308. * :meth:`Context.update() <django.template.Context.update>` can now be used as
  309. a context manager.
  310. * Django template loaders can now extend templates recursively.
  311. * The debug page template postmortem now include output from each engine that
  312. is installed.
  313. * :ref:`Debug page integration <template-debug-integration>` for custom
  314. template engines was added.
  315. * The :class:`~django.template.backends.django.DjangoTemplates` backend gained
  316. the ability to register libraries and builtins explicitly through the
  317. template :setting:`OPTIONS <TEMPLATES-OPTIONS>`.
  318. * The ``timesince`` and ``timeuntil`` filters were improved to deal with leap
  319. years when given large time spans.
  320. * The ``include`` tag now caches parsed templates objects during template
  321. rendering, speeding up reuse in places such as for loops.
  322. Requests and Responses
  323. ^^^^^^^^^^^^^^^^^^^^^^
  324. * Unless :attr:`HttpResponse.reason_phrase
  325. <django.http.HttpResponse.reason_phrase>` is explicitly set, it now is
  326. determined by the current value of :attr:`HttpResponse.status_code
  327. <django.http.HttpResponse.status_code>`. Modifying the value of
  328. ``status_code`` outside of the constructor will also modify the value of
  329. ``reason_phrase``.
  330. * The debug view now shows details of chained exceptions on Python 3.
  331. * The default 40x error views now accept a second positional parameter, the
  332. exception that triggered the view.
  333. * View error handlers now support
  334. :class:`~django.template.response.TemplateResponse`, commonly used with
  335. class-based views.
  336. * Request middleware can now set :attr:`HttpRequest.urlconf
  337. <django.http.HttpRequest.urlconf>` to ``None`` to revert any changes made
  338. by previous middleware and return to using the :setting:`ROOT_URLCONF`.
  339. * The :setting:`DISALLOWED_USER_AGENTS` check in
  340. :class:`~django.middleware.common.CommonMiddleware` now raises a
  341. :class:`~django.core.exceptions.PermissionDenied` exception as opposed to
  342. returning an :class:`~django.http.HttpResponseForbidden` so that
  343. :data:`~django.conf.urls.handler403` is invoked.
  344. Tests
  345. ^^^^^
  346. * Added the :meth:`json() <django.test.Response.json>` method to test client
  347. responses to give access to the response body as JSON.
  348. URLs
  349. ^^^^
  350. * Regular expression lookaround assertions are now allowed in URL patterns.
  351. * The application namespace can now be set using an ``app_name`` attribute
  352. on the included module or object. It can also be set by passing a 2-tuple
  353. of (<list of patterns>, <application namespace>) as the first argument to
  354. :func:`~django.conf.urls.include`.
  355. Validators
  356. ^^^^^^^^^^
  357. * Added :func:`django.core.validators.int_list_validator` to generate
  358. validators of strings containing integers separated with a custom character.
  359. * :class:`~django.core.validators.EmailValidator` now limits the length of
  360. domain name labels to 63 characters per :rfc:`1034`.
  361. Backwards incompatible changes in 1.9
  362. =====================================
  363. .. warning::
  364. In addition to the changes outlined in this section, be sure to review the
  365. :doc:`deprecation timeline </internals/deprecation>` for any features that
  366. have been removed. If you haven't updated your code within the
  367. deprecation timeline for a given feature, its removal may appear as a
  368. backwards incompatible change.
  369. Database backend API
  370. ~~~~~~~~~~~~~~~~~~~~
  371. * A couple of new tests rely on the ability of the backend to introspect column
  372. defaults (returning the result as ``Field.default``). You can set the
  373. ``can_introspect_default`` database feature to ``False`` if your backend
  374. doesn't implement this. You may want to review the implementation on the
  375. backends that Django includes for reference (:ticket:`24245`).
  376. * Registering a global adapter or converter at the level of the DB-API module
  377. to handle time zone information of :class:`~datetime.datetime` values passed
  378. as query parameters or returned as query results on databases that don't
  379. support time zones is discouraged. It can conflict with other libraries.
  380. The recommended way to add a time zone to :class:`~datetime.datetime` values
  381. fetched from the database is to register a converter for ``DateTimeField``
  382. in ``DatabaseOperations.get_db_converters()``.
  383. The ``needs_datetime_string_cast`` database feature was removed. Database
  384. backends that set it must register a converter instead, as explained above.
  385. * The ``DatabaseOperations.value_to_db_<type>()`` methods were renamed to
  386. ``adapt_<type>field_value()`` to mirror the ``convert_<type>field_value()``
  387. methods.
  388. * To use the new ``date`` lookup, third-party database backends may need to
  389. implement the ``DatabaseOperations.datetime_cast_date_sql()`` method.
  390. * The ``DatabaseOperations.time_extract_sql()`` method was added. It calls the
  391. existing ``date_extract_sql()`` method. This method is overridden by the
  392. SQLite backend to add time lookups (hour, minute, second) to
  393. :class:`~django.db.models.TimeField`, and may be needed by third-party
  394. database backends.
  395. Default settings that were tuples are now lists
  396. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  397. The default settings in ``django.conf.global_settings`` were a combination of
  398. lists and tuples. All settings that were formerly tuples are now lists.
  399. ``is_usable`` attribute on template loaders is removed
  400. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  401. Django template loaders previously required an ``is_usable`` attribute to be
  402. defined. If a loader was configured in the template settings and this attribute
  403. was ``False``, the loader would be silently ignored. In practice, this was only
  404. used by the egg loader to detect if setuptools was installed. The ``is_usable``
  405. attribute is now removed and the egg loader instead fails at runtime if
  406. setuptools is not installed.
  407. Related set direct assignment
  408. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  409. :ref:`Direct assignment <direct-assignment>`) used to perform a ``clear()``
  410. followed by a call to ``add()``. This caused needlessly large data changes
  411. and prevented using the :data:`~django.db.models.signals.m2m_changed` signal
  412. to track individual changes in many-to-many relations.
  413. Direct assignment now relies on the the new
  414. :meth:`django.db.models.fields.related.RelatedManager.set()` method on
  415. related managers which by default only processes changes between the
  416. existing related set and the one that's newly assigned. The previous behavior
  417. can be restored by replacing direct assignment by a call to ``set()`` with
  418. the keyword argument ``clear=True``.
  419. ``ModelForm``, and therefore ``ModelAdmin``, internally rely on direct
  420. assignment for many-to-many relations and as a consequence now use the new
  421. behavior.
  422. Filesystem-based template loaders catch more specific exceptions
  423. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  424. When using the :class:`filesystem.Loader <django.template.loaders.filesystem.Loader>`
  425. or :class:`app_directories.Loader <django.template.loaders.app_directories.Loader>`
  426. template loaders, earlier versions of Django raised a
  427. :exc:`~django.template.TemplateDoesNotExist` error if a template source existed
  428. but was unreadable. This could happen under many circumstances, such as if
  429. Django didn't have permissions to open the file, or if the template source was
  430. a directory. Now, Django only silences the exception if the template source
  431. does not exist. All other situations result in the original ``IOError`` being
  432. raised.
  433. HTTP redirects no longer forced to absolute URIs
  434. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  435. Relative redirects are no longer converted to absolute URIs. :rfc:`2616`
  436. required the ``Location`` header in redirect responses to be an absolute URI,
  437. but it has been superseded by :rfc:`7231` which allows relative URIs in
  438. ``Location``, recognizing the actual practice of user agents, almost all of
  439. which support them.
  440. Consequently, the expected URLs passed to ``assertRedirects`` should generally
  441. no longer include the scheme and domain part of the URLs. For example,
  442. ``self.assertRedirects(response, 'http://testserver/some-url/')`` should be
  443. replaced by ``self.assertRedirects(response, '/some-url/')`` (unless the
  444. redirection specifically contained an absolute URL, of course).
  445. Dropped support for PostgreSQL 9.0
  446. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  447. Upstream support for PostgreSQL 9.0 ended in September 2015. As a consequence,
  448. Django 1.9 sets 9.1 as the minimum PostgreSQL version it officially supports.
  449. Template ``LoaderOrigin`` and ``StringOrigin`` are removed
  450. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  451. In previous versions of Django, when a template engine was initialized with
  452. debug as ``True``, an instance of ``django.template.loader.LoaderOrigin`` or
  453. ``django.template.base.StringOrigin`` was set as the origin attribute on the
  454. template object. These classes have been combined into
  455. :class:`~django.template.base.Origin` and is now always set regardless of the
  456. engine debug setting.
  457. .. _default-logging-changes-19:
  458. Changes to the default logging configuration
  459. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  460. To make it easier to write custom logging configurations, Django's default
  461. logging configuration no longer defines 'django.request' and 'django.security'
  462. loggers. Instead, it defines a single 'django' logger with two handlers:
  463. * 'console': filtered at the ``INFO`` level and only active if ``DEBUG=True``.
  464. * 'mail_admins': filtered at the ``ERROR`` level and only active if
  465. ``DEBUG=False``.
  466. If you aren't overriding Django's default logging, you should see minimal
  467. changes in behavior, but you might see some new logging to the ``runserver``
  468. console, for example.
  469. If you are overriding Django's default logging, you should check to see how
  470. your configuration merges with the new defaults.
  471. Removal of time zone aware global adapters and converters for datetimes
  472. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  473. Django no longer registers global adapters and converters for managing time
  474. zone information on :class:`~datetime.datetime` values sent to the database as
  475. query parameters or read from the database in query results. This change
  476. affects projects that meet all the following conditions:
  477. * The :setting:`USE_TZ` setting is ``True``.
  478. * The database is SQLite, MySQL, Oracle, or a third-party database that
  479. doesn't support time zones. In doubt, you can check the value of
  480. ``connection.features.supports_timezones``.
  481. * The code queries the database outside of the ORM, typically with
  482. ``cursor.execute(sql, params)``.
  483. If you're passing aware :class:`~datetime.datetime` parameters to such
  484. queries, you should turn them into naive datetimes in UTC::
  485. from django.utils import timezone
  486. param = timezone.make_naive(param, timezone.utc)
  487. If you fail to do so, Django 1.9 and 2.0 will perform the conversion like
  488. earlier versions but emit a deprecation warning. Django 2.0 won't perform any
  489. conversion, which may result in data corruption.
  490. If you're reading :class:`~datetime.datetime` values from the results, they
  491. will be naive instead of aware. You can compensate as follows::
  492. from django.utils import timezone
  493. value = timezone.make_aware(value, timezone.utc)
  494. You don't need any of this if you're querying the database through the ORM,
  495. even if you're using :meth:`raw() <django.db.models.query.QuerySet.raw>`
  496. queries. The ORM takes care of managing time zone information.
  497. Template tag modules are imported when templates are configured
  498. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  499. The :class:`~django.template.backends.django.DjangoTemplates` backend now
  500. performs discovery on installed template tag modules when instantiated. This
  501. update enables libraries to be provided explicitly via the ``'libraries'``
  502. key of :setting:`OPTIONS <TEMPLATES-OPTIONS>` when defining a
  503. :class:`~django.template.backends.django.DjangoTemplates` backend. Import
  504. or syntax errors in template tag modules now fail early at instantiation time
  505. rather than when a template with a :ttag:`{% load %}<load>` tag is first
  506. compiled.
  507. ``django.template.base.add_to_builtins()`` is removed
  508. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  509. Although it was a private API, projects commonly used ``add_to_builtins()`` to
  510. make template tags and filters available without using the
  511. :ttag:`{% load %}<load>` tag. This API has been formalized. Projects should now
  512. define built-in libraries via the ``'builtins'`` key of :setting:`OPTIONS
  513. <TEMPLATES-OPTIONS>` when defining a
  514. :class:`~django.template.backends.django.DjangoTemplates` backend.
  515. .. _simple-tag-conditional-escape-fix:
  516. ``simple_tag`` now wraps tag output in ``conditional_escape``
  517. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  518. In general, template tags do not autoescape their contents, and this behavior is
  519. :ref:`documented <tags-auto-escaping>`. For tags like
  520. :class:`~django.template.Library.inclusion_tag`, this is not a problem because
  521. the included template will perform autoescaping. For
  522. :class:`~django.template.Library.assignment_tag`, the output will be escaped
  523. when it is used as a variable in the template.
  524. For the intended use cases of :class:`~django.template.Library.simple_tag`,
  525. however, it is very easy to end up with incorrect HTML and possibly an XSS
  526. exploit. For example::
  527. @register.simple_tag(takes_context=True)
  528. def greeting(context):
  529. return "Hello {0}!".format(context['request'].user.first_name)
  530. In older versions of Django, this will be an XSS issue because
  531. ``user.first_name`` is not escaped.
  532. In Django 1.9, this is fixed: if the template context has ``autoescape=True``
  533. set (the default), then ``simple_tag`` will wrap the output of the tag function
  534. with :func:`~django.utils.html.conditional_escape`.
  535. To fix your ``simple_tag``\s, it is best to apply the following practices:
  536. * Any code that generates HTML should use either the template system or
  537. :func:`~django.utils.html.format_html`.
  538. * If the output of a ``simple_tag`` needs escaping, use
  539. :func:`~django.utils.html.escape` or
  540. :func:`~django.utils.html.conditional_escape`.
  541. * If you are absolutely certain that you are outputting HTML from a trusted
  542. source (e.g. a CMS field that stores HTML entered by admins), you can mark it
  543. as such using :func:`~django.utils.safestring.mark_safe`.
  544. Tags that follow these rules will be correct and safe whether they are run on
  545. Django 1.9+ or earlier.
  546. Miscellaneous
  547. ~~~~~~~~~~~~~
  548. * CSS and images in ``contrib.admin`` to support Internet Explorer 6 & 7 have
  549. been removed as these browsers have reached end-of-life.
  550. * The jQuery static files in ``contrib.admin`` have been moved into a
  551. ``vendor/jquery`` subdirectory.
  552. * The text displayed for null columns in the admin changelist ``list_display``
  553. cells has changed from ``(None)`` (or its translated equivalent) to ``-``.
  554. * ``django.http.responses.REASON_PHRASES`` and
  555. ``django.core.handlers.wsgi.STATUS_CODE_TEXT`` have been removed. Use
  556. Python's stdlib instead: :data:`http.client.responses` for Python 3 and
  557. `httplib.responses`_ for Python 2.
  558. .. _`httplib.responses`: https://docs.python.org/2/library/httplib.html#httplib.responses
  559. * ``ValuesQuerySet`` and ``ValuesListQuerySet`` have been removed.
  560. * The ``admin/base.html`` template no longer sets
  561. ``window.__admin_media_prefix__``. Image references in JavaScript that used
  562. that value to construct absolute URLs have been moved to CSS for easier
  563. customization.
  564. * ``CommaSeparatedIntegerField`` validation has been refined to forbid values
  565. like ``','``, ``',1'``, and ``'1,,2'``.
  566. * Form initialization was moved from the :meth:`ProcessFormView.get()
  567. <django.views.generic.edit.ProcessFormView.get>` method to the new
  568. :meth:`FormMixin.get_context_data()
  569. <django.views.generic.edit.FormMixin.get_context_data>` method. This may be
  570. backwards incompatible if you have overridden the ``get_context_data()``
  571. method without calling ``super()``.
  572. * Support for PostGIS 1.5 has been dropped.
  573. * The ``django.contrib.sites.models.Site.domain`` field was changed to be
  574. :attr:`~django.db.models.Field.unique`.
  575. * In order to enforce test isolation, database queries are not allowed
  576. by default in :class:`~django.test.SimpleTestCase` tests anymore. You
  577. can disable this behavior by setting the
  578. :attr:`~django.test.SimpleTestCase.allow_database_queries` class attribute
  579. to ``True`` on your test class.
  580. * :attr:`ResolverMatch.app_name
  581. <django.core.urlresolvers.ResolverMatch.app_name>` was changed to contain
  582. the full namespace path in the case of nested namespaces. For consistency
  583. with :attr:`ResolverMatch.namespace
  584. <django.core.urlresolvers.ResolverMatch.namespace>`, the empty value is now
  585. an empty string instead of ``None``.
  586. * For security hardening, session keys must be at least 8 characters.
  587. * Private function ``django.utils.functional.total_ordering()`` has been
  588. removed. It contained a workaround for a ``functools.total_ordering()`` bug
  589. in Python versions older than 2.7.3.
  590. * XML serialization (either through :djadmin:`dumpdata` or the syndication
  591. framework) used to output any characters it received. Now if the content to
  592. be serialized contains any control characters not allowed in the XML 1.0
  593. standard, the serialization will fail with a :exc:`ValueError`.
  594. .. _deprecated-features-1.9:
  595. Features deprecated in 1.9
  596. ==========================
  597. ``assignment_tag()``
  598. ~~~~~~~~~~~~~~~~~~~~
  599. Django 1.4 added the ``assignment_tag`` helper to ease the creation of
  600. template tags that store results in a template variable. The
  601. :meth:`~django.template.Library.simple_tag` helper has gained this same
  602. ability, making the ``assignment_tag`` obsolete. Tags that use
  603. ``assignment_tag`` should be updated to use ``simple_tag``.
  604. ``{% cycle %}`` syntax with comma-separated arguments
  605. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  606. The :ttag:`cycle` tag supports an inferior old syntax from previous Django
  607. versions:
  608. .. code-block:: html+django
  609. {% cycle row1,row2,row3 %}
  610. Its parsing caused bugs with the current syntax, so support for the old syntax
  611. will be removed in Django 2.0 following an accelerated deprecation.
  612. ``Field.rel`` changes
  613. ~~~~~~~~~~~~~~~~~~~~~
  614. ``Field.rel`` and its methods and attributes have changed to match the related
  615. fields API. The ``Field.rel`` attribute is renamed to ``remote_field`` and many
  616. of its methods and attributes are either changed or renamed.
  617. The aim of these changes is to provide a documented API for relation fields.
  618. ``GeoManager`` and ``GeoQuerySet`` custom methods
  619. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  620. All custom ``GeoQuerySet`` methods (``area()``, ``distance()``, ``gml()``, ...)
  621. have been replaced by equivalent geographic expressions in annotations (see in
  622. new features). Hence the need to set a custom ``GeoManager`` to GIS-enabled
  623. models is now obsolete. As soon as your code doesn't call any of the deprecated
  624. methods, you can simply remove the ``objects = GeoManager()`` lines from your
  625. models.
  626. Template loader APIs have changed
  627. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  628. Django template loaders have been updated to allow recursive template
  629. extending. This change necessitated a new template loader API. The old
  630. ``load_template()`` and ``load_template_sources()`` methods are now deprecated.
  631. Details about the new API can be found :ref:`in the template loader
  632. documentation <custom-template-loaders>`.
  633. Passing a 3-tuple or an ``app_name`` to :func:`~django.conf.urls.include()`
  634. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  635. The instance namespace part of passing a tuple as the first argument has been
  636. replaced by passing the ``namespace`` argument to ``include()``. The
  637. ``app_name`` argument to ``include()`` has been replaced by passing a 2-tuple,
  638. or passing an object or module with an ``app_name`` attribute.
  639. If the ``app_name`` is set in this new way, the ``namespace`` argument is no
  640. longer required. It will default to the value of ``app_name``.
  641. This change also means that the old way of including an ``AdminSite`` instance
  642. is deprecated. Instead, pass ``admin.site.urls`` directly to
  643. :func:`~django.conf.urls.url()`:
  644. .. snippet::
  645. :filename: urls.py
  646. from django.conf.urls import url
  647. from django.contrib import admin
  648. urlpatterns = [
  649. url(r'^admin/', admin.site.urls),
  650. ]
  651. URL application namespace required if setting an instance namespace
  652. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  653. In the past, an instance namespace without an application namespace
  654. would serve the same purpose as the application namespace, but it was
  655. impossible to reverse the patterns if there was an application namespace
  656. with the same name. Includes that specify an instance namespace require that
  657. the included URLconf sets an application namespace.
  658. Miscellaneous
  659. ~~~~~~~~~~~~~
  660. * The ``weak`` argument to ``django.dispatch.signals.Signal.disconnect()`` has
  661. been deprecated as it has no effect.
  662. * The ``check_aggregate_support()`` method of
  663. ``django.db.backends.base.BaseDatabaseOperations`` has been deprecated and
  664. will be removed in Django 2.0. The more general ``check_expression_support()``
  665. should be used instead.
  666. * ``django.forms.extras`` is deprecated. You can find
  667. :class:`~django.forms.SelectDateWidget` in ``django.forms.widgets``
  668. (or simply ``django.forms``) instead.
  669. * Private API ``django.db.models.fields.add_lazy_relation()`` is deprecated.
  670. * The ``django.contrib.auth.tests.utils.skipIfCustomUser()`` decorator is
  671. deprecated. With the test discovery changes in Django 1.6, the tests for
  672. ``django.contrib`` apps are no longer run as part of the user's project.
  673. Therefore, the ``@skipIfCustomUser`` decorator is no longer needed to
  674. decorate tests in ``django.contrib.auth``.
  675. * If you customized some :ref:`error handlers <error-views>`, the view
  676. signatures with only one request parameter are deprecated. The views should
  677. now also accept a second ``exception`` positional parameter.
  678. * The ``django.utils.feedgenerator.Atom1Feed.mime_type`` and
  679. ``django.utils.feedgenerator.RssFeed.mime_type`` attributes are deprecated in
  680. favor of ``content_type``.
  681. .. removed-features-1.9:
  682. Features removed in 1.9
  683. =======================
  684. These features have reached the end of their deprecation cycle and so have been
  685. removed in Django 1.9 (please see the :ref:`deprecation timeline
  686. <deprecation-removed-in-1.9>` for more details):
  687. * ``django.utils.dictconfig`` is removed.
  688. * ``django.utils.importlib`` is removed.
  689. * ``django.utils.tzinfo`` is removed.
  690. * ``django.utils.unittest`` is removed.
  691. * The ``syncdb`` command is removed.
  692. * ``django.db.models.signals.pre_syncdb`` and
  693. ``django.db.models.signals.post_syncdb`` is removed.
  694. * Support for ``allow_syncdb`` on database routers is removed.
  695. * The legacy method of syncing apps without migrations is removed,
  696. and migrations are compulsory for all apps. This includes automatic
  697. loading of ``initial_data`` fixtures and support for initial SQL data.
  698. * All models need to be defined inside an installed application or declare an
  699. explicit :attr:`~django.db.models.Options.app_label`. Furthermore, it isn't
  700. possible to import them before their application is loaded. In particular, it
  701. isn't possible to import models inside the root package of an application.
  702. * The model and form ``IPAddressField`` is removed. A stub field remains for
  703. compatibility with historical migrations.
  704. * ``AppCommand.handle_app()`` is no longer be supported.
  705. * ``RequestSite`` and ``get_current_site()`` are no longer importable from
  706. ``django.contrib.sites.models``.
  707. * FastCGI support via the ``runfcgi`` management command is removed.
  708. * ``django.utils.datastructures.SortedDict`` is removed.
  709. * ``ModelAdmin.declared_fieldsets`` is removed.
  710. * The ``util`` modules that provided backwards compatibility are removed:
  711. * ``django.contrib.admin.util``
  712. * ``django.contrib.gis.db.backends.util``
  713. * ``django.db.backends.util``
  714. * ``django.forms.util``
  715. * ``ModelAdmin.get_formsets`` is removed.
  716. * The backward compatible shims introduced to rename the
  717. ``BaseMemcachedCache._get_memcache_timeout()`` method to
  718. ``get_backend_timeout()`` is removed.
  719. * The ``--natural`` and ``-n`` options for :djadmin:`dumpdata` are removed.
  720. * The ``use_natural_keys`` argument for ``serializers.serialize()`` is removed.
  721. * Private API ``django.forms.forms.get_declared_fields()`` is removed.
  722. * The ability to use a ``SplitDateTimeWidget`` with ``DateTimeField`` is
  723. removed.
  724. * The ``WSGIRequest.REQUEST`` property is removed.
  725. * The class ``django.utils.datastructures.MergeDict`` is removed.
  726. * The ``zh-cn`` and ``zh-tw`` language codes are removed.
  727. * The internal ``django.utils.functional.memoize()`` is removed.
  728. * ``django.core.cache.get_cache`` is removed.
  729. * ``django.db.models.loading`` is removed.
  730. * Passing callable arguments to querysets is no longer possible.
  731. * ``BaseCommand.requires_model_validation`` is removed in favor of
  732. ``requires_system_checks``. Admin validators is replaced by admin checks.
  733. * The ``ModelAdmin.validator_class`` and ``default_validator_class`` attributes
  734. are removed.
  735. * ``ModelAdmin.validate()`` is removed.
  736. * ``django.db.backends.DatabaseValidation.validate_field`` is removed in
  737. favor of the ``check_field`` method.
  738. * The ``validate`` management command is removed.
  739. * ``django.utils.module_loading.import_by_path`` is removed in favor of
  740. ``django.utils.module_loading.import_string``.
  741. * ``ssi`` and ``url`` template tags are removed from the ``future`` template
  742. tag library.
  743. * ``django.utils.text.javascript_quote()`` is removed.
  744. * Database test settings as independent entries in the database settings,
  745. prefixed by ``TEST_``, are no longer supported.
  746. * The `cache_choices` option to :class:`~django.forms.ModelChoiceField` and
  747. :class:`~django.forms.ModelMultipleChoiceField` is removed.
  748. * The default value of the
  749. :attr:`RedirectView.permanent <django.views.generic.base.RedirectView.permanent>`
  750. attribute has changed from ``True`` to ``False``.
  751. * ``django.contrib.sitemaps.FlatPageSitemap`` is removed in favor of
  752. ``django.contrib.flatpages.sitemaps.FlatPageSitemap``.
  753. * Private API ``django.test.utils.TestTemplateLoader`` is removed.
  754. * The ``django.contrib.contenttypes.generic`` module is removed.