1.9.txt 61 KB

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