1.9.txt 35 KB

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