1.8.txt 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. ============================================
  2. Django 1.8 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. Welcome to Django 1.8!
  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.6 or older versions. We've also dropped some features, which are detailed in
  8. :ref:`our deprecation plan <deprecation-removed-in-1.8>`, and we've `begun the
  9. deprecation process for some features`_.
  10. .. _`new features`: `What's new in Django 1.8`_
  11. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.8`_
  12. .. _`begun the deprecation process for some features`: `Features deprecated in 1.8`_
  13. Python compatibility
  14. ====================
  15. Like Django 1.7, Django 1.8 requires Python 2.7 or above, though we
  16. **highly recommend** the latest minor release.
  17. What's new in Django 1.8
  18. ========================
  19. ...
  20. Minor features
  21. ~~~~~~~~~~~~~~
  22. :mod:`django.contrib.admin`
  23. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  24. * :class:`~django.contrib.admin.ModelAdmin` now has a
  25. :meth:`~django.contrib.admin.ModelAdmin.has_module_permission`
  26. method to allow limiting access to the module on the admin index page.
  27. * :class:`~django.contrib.admin.InlineModelAdmin` now has an attribute
  28. :attr:`~django.contrib.admin.InlineModelAdmin.show_change_link` that
  29. supports showing a link to an inline object's change form.
  30. * Use the new ``django.contrib.admin.RelatedOnlyFieldListFilter`` in
  31. :attr:`ModelAdmin.list_filter <django.contrib.admin.ModelAdmin.list_filter>`
  32. to limit the ``list_filter`` choices to foreign objects which are attached to
  33. those from the ``ModelAdmin``.
  34. * The :meth:`ModelAdmin.delete_view()
  35. <django.contrib.admin.ModelAdmin.delete_view>` displays a summary of objects
  36. to be deleted on the deletion confirmation page.
  37. :mod:`django.contrib.auth`
  38. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  39. * Authorization backends can now raise
  40. :class:`~django.core.exceptions.PermissionDenied` in
  41. :meth:`~django.contrib.auth.models.User.has_perm`
  42. and :meth:`~django.contrib.auth.models.User.has_module_perms`
  43. to short-circuit permission checking.
  44. * :class:`~django.contrib.auth.forms.PasswordResetForm` now
  45. has a method :meth:`~django.contrib.auth.forms.PasswordResetForm.send_email`
  46. that can be overridden to customize the mail to be sent.
  47. * The ``max_length`` of :attr:`Permission.name
  48. <django.contrib.auth.models.Permission.name>` has been increased from 50 to
  49. 255 characters. Please run the database migration.
  50. * :attr:`~django.contrib.auth.models.CustomUser.USERNAME_FIELD` and
  51. :attr:`~django.contrib.auth.models.CustomUser.REQUIRED_FIELDS` now supports
  52. :class:`~django.db.models.ForeignKey`\s.
  53. :mod:`django.contrib.formtools`
  54. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  55. * A :doc:`form wizard </ref/contrib/formtools/form-wizard>` using the
  56. :class:`~django.contrib.formtools.wizard.views.CookieWizardView` will now ignore
  57. an invalid cookie, and the wizard will restart from the first step. An invalid
  58. cookie can occur in cases of intentional manipulation, but also after a secret
  59. key change. Previously, this would raise ``WizardViewCookieModified``, a
  60. ``SuspiciousOperation``, causing an exception for any user with an invalid cookie
  61. upon every request to the wizard, until the cookie is removed.
  62. :mod:`django.contrib.gis`
  63. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  64. * Compatibility shims for ``SpatialRefSys`` and ``GeometryColumns`` changed in
  65. Django 1.2 have been removed.
  66. :mod:`django.contrib.messages`
  67. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  68. * ...
  69. :mod:`django.contrib.redirects`
  70. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  71. * ...
  72. :mod:`django.contrib.sessions`
  73. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  74. * Session cookie is now deleted after
  75. :meth:`~django.contrib.sessions.backends.base.SessionBase.flush()` is called.
  76. :mod:`django.contrib.sitemaps`
  77. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  78. * The new :attr:`Sitemap.i18n <django.contrib.sitemaps.Sitemap.i18n>` attribute
  79. allows you to generate a sitemap based on the :setting:`LANGUAGES` setting.
  80. :mod:`django.contrib.sites`
  81. ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  82. * ...
  83. :mod:`django.contrib.staticfiles`
  84. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  85. * ...
  86. :mod:`django.contrib.syndication`
  87. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  88. * ...
  89. Cache
  90. ^^^^^
  91. * ...
  92. Email
  93. ^^^^^
  94. * :ref:`Email backends <topic-email-backends>` now support the context manager
  95. protocol for opening and closing connections.
  96. File Storage
  97. ^^^^^^^^^^^^
  98. * ...
  99. File Uploads
  100. ^^^^^^^^^^^^
  101. * ...
  102. Forms
  103. ^^^^^
  104. * Form widgets now render attributes with a value of ``True`` or ``False``
  105. as HTML5 boolean attributes.
  106. * The new :meth:`~django.forms.Form.has_error()` method allows checking
  107. if a specific error has happened.
  108. * If :attr:`~django.forms.Form.required_css_class` is defined on a form, then
  109. the ``<label>`` tags for required fields will have this class present in its
  110. attributes.
  111. * The rendering of non-field errors in unordered lists (``<ul>``) now includes
  112. ``nonfield`` in its list of classes to distinguish them from field-specific
  113. errors.
  114. * :class:`~django.forms.Field` now accepts a
  115. :attr:`~django.forms.Field.label_suffix` argument, which will override the
  116. form's :attr:`~django.forms.Form.label_suffix`. This enables customizing the
  117. suffix on a per-field basis — previously it wasn't possible to override
  118. a form's :attr:`~django.forms.Form.label_suffix` while using shortcuts such
  119. as ``{{ form.as_p }}`` in templates.
  120. * :class:`~django.forms.extras.widgets.SelectDateWidget` now accepts an
  121. :attr:`~django.forms.extras.widgets.SelectDateWidget.empty_label` argument, which will
  122. override the top list choice label when :class:`~django.forms.DateField` is not required.
  123. * After an :class:`~django.forms.ImageField` has been cleaned and validated, the
  124. ``UploadedFile`` object will have an additional ``image`` attribute containing
  125. the Pillow ``Image`` instance used to check if the file was a valid image. It
  126. will also update ``UploadedFile.content_type`` with the image's content type
  127. as determined by Pillow.
  128. Generic Views
  129. ^^^^^^^^^^^^^
  130. * Generic views that use :class:`~django.views.generic.list.MultipleObjectMixin`
  131. may now specify the ordering applied to the
  132. :attr:`~django.views.generic.list.MultipleObjectMixin.queryset` by setting
  133. :attr:`~django.views.generic.list.MultipleObjectMixin.ordering` or overriding
  134. :meth:`~django.views.generic.list.MultipleObjectMixin.get_ordering()`.
  135. Internationalization
  136. ^^^^^^^^^^^^^^^^^^^^
  137. * :setting:`FORMAT_MODULE_PATH` can now be a list of strings representing
  138. module paths. This allows importing several format modules from different
  139. reusable apps. It also allows overriding those custom formats in your main
  140. Django project.
  141. Management Commands
  142. ^^^^^^^^^^^^^^^^^^^
  143. * :djadmin:`dumpdata` now has the option :djadminopt:`--output` which allows
  144. specifying the file to which the serialized data is written.
  145. * :djadmin:`makemessages` and :djadmin:`compilemessages` now have the option
  146. :djadminopt:`--exclude` which allows exclusion of specific locales from
  147. processing.
  148. * The :djadminopt:`--ignorenonexistent` option of the :djadmin:`loaddata`
  149. management command now ignores data for models that no longer exist.
  150. * :djadmin:`runserver` now uses daemon threads for faster reloading.
  151. * :djadmin:`inspectdb` now outputs ``Meta.unique_together``.
  152. * When calling management commands from code through :ref:`call_command
  153. <call-command>` and passing options, the option name can match the command
  154. line option name (without the initial dashes) or the final option destination
  155. variable name, but in either case, the resulting option received by the
  156. command is now always the ``dest`` name specified in the command option
  157. definition (as long as the command uses the new :py:mod:`argparse` module).
  158. * The :djadmin:`dbshell` command now supports MySQL's optional SSL certificate
  159. authority setting (``--ssl-ca``).
  160. Models
  161. ^^^^^^
  162. * Django now logs at most 9000 queries in ``connections.queries``, in order
  163. to prevent excessive memory usage in long-running processes in debug mode.
  164. * There is now a model ``Meta`` option to define a
  165. :attr:`default related name <django.db.models.Options.default_related_name>`
  166. for all relational fields of a model.
  167. * Pickling models and querysets across different versions of Django isn't
  168. officially supported (it may work, but there's no guarantee). An extra
  169. variable that specifies the current Django version is now added to the
  170. pickled state of models and querysets, and Django raises a ``RuntimeWarning``
  171. when these objects are unpickled in a different version than the one in
  172. which they were pickled.
  173. * Added :meth:`Model.from_db() <django.db.models.Model.from_db()>` which
  174. Django uses whenever objects are loaded using the ORM. The method allows
  175. customizing model loading behavior.
  176. Signals
  177. ^^^^^^^
  178. * Exceptions from the ``(receiver, exception)`` tuples returned by
  179. :meth:`Signal.send_robust() <django.dispatch.Signal.send_robust>` now have
  180. their traceback attached as a ``__traceback__`` attribute.
  181. Templates
  182. ^^^^^^^^^
  183. * :tfilter:`urlize` now supports domain-only links that include characters after
  184. the top-level domain (e.g. ``djangoproject.com/`` and
  185. ``djangoproject.com/download/``).
  186. Requests and Responses
  187. ^^^^^^^^^^^^^^^^^^^^^^
  188. * ``WSGIRequest`` now respects paths starting with ``//``.
  189. * The :meth:`HttpRequest.build_absolute_uri()
  190. <django.http.HttpRequest.build_absolute_uri>` method now handles paths
  191. starting with ``//`` correctly.
  192. * If :setting:`DEBUG` is ``True`` and a request raises a
  193. :exc:`~django.core.exceptions.SuspiciousOperation`, the response will be
  194. rendered with a detailed error page.
  195. * The ``query_string`` argument of :class:`~django.http.QueryDict` is now
  196. optional, defaulting to ``None``, so a blank ``QueryDict`` can now be
  197. instantiated with ``QueryDict()`` instead of ``QueryDict(None)`` or
  198. ``QueryDict('')``.
  199. * The ``GET`` and ``POST`` attributes of an :class:`~django.http.HttpRequest`
  200. object are now :class:`~django.http.QueryDict`\s rather than dictionaries,
  201. and the ``FILES`` attribute is now a ``MultiValueDict``.
  202. This brings this class into line with the documentation and with
  203. ``WSGIRequest``.
  204. * The :attr:`HttpResponse.charset <django.http.HttpResponse.charset>` attribute
  205. was added.
  206. Tests
  207. ^^^^^
  208. * The ``count`` argument was added to
  209. :meth:`~django.test.SimpleTestCase.assertTemplateUsed`. This allows you to
  210. assert that a template was rendered a specific number of times.
  211. * The new :meth:`~django.test.SimpleTestCase.assertJSONNotEqual` assertion
  212. allows you to test that two JSON fragments are not equal.
  213. * Added the ability to preserve the test database by adding the
  214. :djadminopt:`--keepdb` flag.
  215. * Added the :attr:`~django.test.Response.resolver_match` attribute to test
  216. client responses.
  217. Validators
  218. ^^^^^^^^^^
  219. * ...
  220. Backwards incompatible changes in 1.8
  221. =====================================
  222. .. warning::
  223. In addition to the changes outlined in this section, be sure to review the
  224. :ref:`deprecation plan <deprecation-removed-in-1.8>` for any features that
  225. have been removed. If you haven't updated your code within the
  226. deprecation timeline for a given feature, its removal may appear as a
  227. backwards incompatible change.
  228. Related object operations are run in a transaction
  229. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  230. Some operations on related objects such as
  231. :meth:`~django.db.models.fields.related.RelatedManager.add()` or
  232. :ref:`direct assignment<direct-assignment>` ran multiple data modifying
  233. queries without wrapping them in transactions. To reduce the risk of data
  234. corruption, all data modifying methods that affect multiple related objects
  235. (i.e. ``add()``, ``remove()``, ``clear()``, and :ref:`direct assignment
  236. <direct-assignment>`) now perform their data modifying queries from within a
  237. transaction, provided your database supports transactions.
  238. This has one backwards incompatible side effect, signal handlers triggered from
  239. these methods are now executed within the method's transaction and any
  240. exception in a signal handler will prevent the whole operation.
  241. Assigning unsaved objects to relations raises an error
  242. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  243. Assigning unsaved objects to a :class:`~django.db.models.ForeignKey`,
  244. :class:`~django.contrib.contenttypes.fields.GenericForeignKey`, and
  245. :class:`~django.db.models.OneToOneField` now raises a :exc:`ValueError`.
  246. Previously, the assignment of an unsaved object would be silently ignored.
  247. For example::
  248. >>> book = Book.objects.create(name="Django")
  249. >>> book.author = Author(name="John")
  250. >>> book.author.save()
  251. >>> book.save()
  252. >>> Book.objects.get(name="Django")
  253. >>> book.author
  254. >>>
  255. Now, an error will be raised to prevent data loss::
  256. >>> book.author = Author(name="john")
  257. Traceback (most recent call last):
  258. ...
  259. ValueError: Cannot assign "<Author: John>": "Author" instance isn't saved in the database.
  260. Management commands that only accept positional arguments
  261. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  262. If you have written a custom management command that only accepts positional
  263. arguments and you didn't specify the
  264. :attr:`~django.core.management.BaseCommand.args` command variable, you might
  265. get an error like ``Error: unrecognized arguments: ...``, as variable parsing
  266. is now based on :py:mod:`argparse` which doesn't implicitly accept positional
  267. arguments. You can make your command backwards compatible by simply setting the
  268. :attr:`~django.core.management.BaseCommand.args` class variable. However, if
  269. you don't have to keep compatibility with older Django versions, it's better to
  270. implement the new :meth:`~django.core.management.BaseCommand.add_arguments`
  271. method as described in :doc:`/howto/custom-management-commands`.
  272. Custom test management command arguments through test runner
  273. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  274. The method to add custom arguments to the `test` management command through the
  275. test runner has changed. Previously, you could provide an `option_list` class
  276. variable on the test runner to add more arguments (à la :py:mod:`optparse`).
  277. Now to implement the same behavior, you have to create an
  278. ``add_arguments(cls, parser)`` class method on the test runner and call
  279. ``parser.add_argument`` to add any custom arguments, as parser is now an
  280. :py:class:`argparse.ArgumentParser` instance.
  281. Model check ensures auto-generated column names are within limits specified by database
  282. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  283. A field name that's longer than the column name length supported by a database
  284. can create problems. For example, with MySQL you'll get an exception trying to
  285. create the column, and with PostgreSQL the column name is truncated by the
  286. database (you may see a warning in the PostgreSQL logs).
  287. A model check has been introduced to better alert users to this scenario before
  288. the actual creation of database tables.
  289. If you have an existing model where this check seems to be a false positive,
  290. for example on PostgreSQL where the name was already being truncated, simply
  291. use :attr:`~django.db.models.Field.db_column` to specify the name that's being
  292. used.
  293. The check also applies to the columns generated in an implicit
  294. ``ManyToManyField.through`` model. If you run into an issue there, use
  295. :attr:`~django.db.models.ManyToManyField.through` to create an explicit model
  296. and then specify :attr:`~django.db.models.Field.db_column` on its column(s)
  297. as needed.
  298. Query relation lookups now check object types
  299. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  300. Querying for model lookups now checks if the object passed is of correct type
  301. and raises a :exc:`ValueError` if not. Previously, Django didn't care if the
  302. object was of correct type; it just used the object's related field attribute
  303. (e.g. ``id``) for the lookup. Now, an error is raised to prevent incorrect
  304. lookups::
  305. >>> book = Book.objects.create(name="Django")
  306. >>> book = Book.objects.filter(author=book)
  307. Traceback (most recent call last):
  308. ...
  309. ValueError: Cannot query "<Book: Django>": Must be "Author" instance.
  310. Default ``EmailField.max_length`` increased to 254
  311. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  312. The old default 75 character ``max_length`` was not capable of storing all
  313. possible RFC3696/5321-compliant email addresses. In order to store all
  314. possible valid email addresses, the ``max_length`` has been increased to 254
  315. characters. You will need to generate and apply database migrations for your
  316. affected models (or add ``max_length=75`` if you wish to keep the length on
  317. your current fields). A migration for
  318. :attr:`django.contrib.auth.models.User.email` is included.
  319. Support for PostgreSQL versions older than 9.0
  320. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  321. The end of upstream support periods was reached in July 2014 for PostgreSQL 8.4.
  322. As a consequence, Django 1.8 sets 9.0 as the minimum PostgreSQL version it
  323. officially supports.
  324. This also includes dropping support for PostGIS 1.3 and 1.4 as these versions
  325. are not supported on versions of PostgreSQL later than 8.4.
  326. Support for MySQL versions older than 5.5
  327. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  328. The end of upstream support periods was reached in January 2012 for MySQL 5.0
  329. and December 2013 for MySQL 5.1. As a consequence, Django 1.8 sets 5.5 as the
  330. minimum MySQL version it officially supports.
  331. Support for Oracle versions older than 11.1
  332. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  333. The end of upstream support periods was reached in July 2010 for Oracle 9.2,
  334. January 2012 for Oracle 10.1, and July 2013 for Oracle 10.2. As a consequence,
  335. Django 1.8 sets 11.1 as the minimum Oracle version it officially supports.
  336. ``AbstractUser.last_login`` allows null values
  337. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  338. The :attr:`AbstractUser.last_login <django.contrib.auth.models.User.last_login>`
  339. field now allows null values. Previously, it defaulted to the time when the user
  340. was created which was misleading if the user never logged in. Please run the
  341. database migration. If your custom user inherits from ``AbstractUser`` and you
  342. wish to set ``last_login`` to ``NULL`` for users who haven't logged in, you can
  343. run this query::
  344. from django.db import models
  345. from django.contrib.auth import get_user_model
  346. from django.contrib.auth.models import AbstractBaseUser
  347. UserModel = get_user_model()
  348. if issubclass(UserModel, AbstractBaseUser):
  349. UserModel._default_manager.filter(
  350. last_login=models.F('date_joined')
  351. ).update(last_login=None)
  352. Miscellaneous
  353. ~~~~~~~~~~~~~
  354. * ``connections.queries`` is now a read-only attribute.
  355. * Database connections are considered equal only if they're the same object.
  356. They aren't hashable any more.
  357. * :class:`~django.middleware.gzip.GZipMiddleware` used to disable compression
  358. for some content types when the request is from Internet Explorer, in order
  359. to work around a bug in IE6 and earlier. This behavior could affect
  360. performance on IE7 and later. It was removed.
  361. * ``URLField.to_python`` no longer adds a trailing slash to pathless URLs.
  362. * ``django.contrib.gis`` dropped support for GEOS 3.1 and GDAL 1.6.
  363. * The :tfilter:`length` template filter now returns ``0`` for an undefined
  364. variable, rather than an empty string.
  365. * Support for SpatiaLite < 2.4 has been dropped.
  366. * ``ForeignKey.default_error_message['invalid']`` has been changed from
  367. ``'%(model)s instance with pk %(pk)r does not exist.'`` to
  368. ``'%(model)s instance with %(field)s %(value)r does not exist.'`` If you are
  369. using this message in your own code, please update the list of interpolated
  370. parameters. Internally, Django will continue to provide the
  371. ``pk`` parameter in ``params`` for backwards compatibility.
  372. * ``UserCreationForm.errors_messages['duplicate_username']`` is no longer used.
  373. If you wish to customize that error message, :ref:`override it on the form
  374. <modelforms-overriding-default-fields>` using the ``'unique'`` key in
  375. ``Meta.errors_messages['username']`` or, if you have a custom form field for
  376. ``'username'``, using the the ``'unique'`` key in its
  377. :attr:`~django.forms.Field.error_messages` argument.
  378. * ``AdminSite`` no longer takes an ``app_name`` argument and its ``app_name``
  379. attribute has been removed. The application name is always ``admin`` (as
  380. opposed to the instance name which you can still customize using
  381. ``AdminSite(name="...")``.
  382. .. _deprecated-features-1.8:
  383. Features deprecated in 1.8
  384. ==========================
  385. Loading ``cycle`` and ``firstof`` template tags from ``future`` library
  386. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  387. Django 1.6 introduced ``{% load cycle from future %}`` and
  388. ``{% load firstof from future %}`` syntax for forward compatibility of the
  389. :ttag:`cycle` and :ttag:`firstof` template tags. This syntax is now deprecated
  390. and will be removed in Django 2.0. You can simply remove the
  391. ``{% load ... from future %}`` tags.
  392. ``django.conf.urls.patterns()``
  393. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  394. In the olden days of Django, it was encouraged to reference views as strings
  395. in ``urlpatterns``::
  396. urlpatterns = patterns('',
  397. url('^$', 'myapp.views.myview'),
  398. )
  399. and Django would magically import ``myapp.views.myview`` internally and turn
  400. the string into a real function reference. In order to reduce repetition when
  401. referencing many views from the same module, the ``patterns()`` function takes
  402. a required initial ``prefix`` argument which is prepended to all
  403. views-as-strings in that set of ``urlpatterns``::
  404. urlpatterns = patterns('myapp.views',
  405. url('^$', 'myview'),
  406. url('^other/$', 'otherview'),
  407. )
  408. In the modern era, we have updated the tutorial to instead recommend importing
  409. your views module and referencing your view functions (or classes) directly.
  410. This has a number of advantages, all deriving from the fact that we are using
  411. normal Python in place of "Django String Magic": the errors when you mistype a
  412. view name are less obscure, IDEs can help with autocompletion of view names,
  413. etc.
  414. So these days, the above use of the ``prefix`` arg is much more likely to be
  415. written (and is better written) as::
  416. from myapp import views
  417. urlpatterns = patterns('',
  418. url('^$', views.myview),
  419. url('^other/$', views.otherview),
  420. )
  421. Thus ``patterns()`` serves little purpose and is a burden when teaching new users
  422. (answering the newbie's question "why do I need this empty string as the first
  423. argument to ``patterns()``?"). For these reasons, we are deprecating it.
  424. Updating your code is as simple as ensuring that ``urlpatterns`` is a list of
  425. :func:`django.conf.urls.url` instances. For example::
  426. from django.conf.urls import url
  427. from myapp import views
  428. urlpatterns = [
  429. url('^$', views.myview),
  430. url('^other/$', views.otherview),
  431. ]
  432. Passing a string as ``view`` to :func:`~django.conf.urls.url`
  433. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  434. Related to the previous item, referencing views as strings in the ``url()``
  435. function is deprecated. Pass the callable view as described in the previous
  436. section instead.
  437. ``django.test.SimpleTestCase.urls``
  438. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  439. The attribute :attr:`SimpleTestCase.urls <django.test.SimpleTestCase.urls>`
  440. for specifying URLconf configuration in tests has been deprecated and will be
  441. removed in Django 2.0. Use :func:`@override_settings(ROOT_URLCONF=...)
  442. <django.test.override_settings>` instead.
  443. ``prefix`` argument to :func:`~django.conf.urls.i18n.i18n_patterns`
  444. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  445. Related to the previous item, the ``prefix`` argument to
  446. :func:`django.conf.urls.i18n.i18n_patterns` has been deprecated. Simply pass a
  447. list of :func:`django.conf.urls.url` instances instead.
  448. Using an incorrect count of unpacked values in the :ttag:`for` template tag
  449. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  450. Using an incorrect count of unpacked values in :ttag:`for` tag will raise an
  451. exception rather than fail silently in Django 2.0.
  452. Passing a dotted path to :func:`~django.core.urlresolvers.reverse()` and :ttag:`url`
  453. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  454. Reversing URLs by Python path is an expensive operation as it causes the
  455. path being reversed to be imported. This behavior has also resulted in a
  456. `security issue`_. Use :ref:`named URL patterns <naming-url-patterns>`
  457. for reversing instead.
  458. If you are using :mod:`django.contrib.sitemaps`, add the ``name`` argument to
  459. the ``url`` that references :func:`django.contrib.sitemaps.views.sitemap`::
  460. from django.contrib.sitemaps.views import sitemap
  461. url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
  462. name='django.contrib.sitemaps.views.sitemap')
  463. to ensure compatibility when reversing by Python path is removed in Django 2.0.
  464. Similarly for GIS sitemaps, add ``name='django.contrib.gis.sitemaps.views.kml'``
  465. or ``name='django.contrib.gis.sitemaps.views.kmz'``.
  466. .. _security issue: https://www.djangoproject.com/weblog/2014/apr/21/security/#s-issue-unexpected-code-execution-using-reverse
  467. Extending management command arguments through ``Command.option_list``
  468. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  469. Management commands now use :py:mod:`argparse` instead of :py:mod:`optparse` to
  470. parse command-line arguments passed to commands. This also means that the way
  471. to add custom arguments to commands has changed: instead of extending the
  472. ``option_list`` class list, you should now override the
  473. :meth:`~django.core.management.BaseCommand.add_arguments` method and add
  474. arguments through ``argparse.add_argument()``. See
  475. :ref:`this example <custom-commands-options>` for more details.
  476. ``django.core.management.NoArgsCommand``
  477. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  478. The class :class:`~django.core.management.NoArgsCommand` is now deprecated and
  479. will be removed in Django 2.0. Use :class:`~django.core.management.BaseCommand`
  480. instead, which takes no arguments by default.
  481. ``cache_choices`` option of ``ModelChoiceField`` and ``ModelMultipleChoiceField``
  482. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  483. :class:`~django.forms.ModelChoiceField` and
  484. :class:`~django.forms.ModelMultipleChoiceField` took an undocumented, untested
  485. option ``cache_choices``. This cached querysets between multiple renderings of
  486. the same ``Form`` object. This option is subject to an accelerated deprecation
  487. and will be removed in Django 1.9.
  488. ``django.template.resolve_variable()``
  489. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  490. The function has been informally marked as "Deprecated" for some time. Replace
  491. ``resolve_variable(path, context)`` with
  492. ``django.template.Variable(path).resolve(context)``.
  493. ``django.contrib.webdesign``
  494. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  495. It provided the :ttag:`lorem` template tag which is now included in the
  496. built-in tags. Simply remove ``'django.contrib.webdesign'`` from
  497. :setting:`INSTALLED_APPS` and ``{% load webdesign %}`` from your templates.
  498. ``error_message`` argument to ``django.forms.RegexField``
  499. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  500. It provided backwards compatibility for pre-1.0 code, but its functionality is
  501. redundant. Use ``Field.error_messages['invalid']`` instead.
  502. Old :tfilter:`unordered_list` syntax
  503. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  504. An older (pre-1.0), more restrictive and verbose input format for the
  505. :tfilter:`unordered_list` template filter has been deprecated::
  506. ``['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]``
  507. Using the new syntax, this becomes::
  508. ``['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]``
  509. ``django.forms.Field._has_changed()``
  510. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  511. Rename this method to :meth:`~django.forms.Field.has_changed` by removing the
  512. leading underscore. The old name will still work until Django 2.0.
  513. ``django.utils.html.remove_tags()`` and ``removetags`` template filter
  514. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  515. ``django.utils.html.remove_tags()`` as well as the template filter
  516. ``removetags`` have been deprecated as they cannot guarantee safe output. Their
  517. existence is likely to lead to their use in security-sensitive contexts where
  518. they are not actually safe.
  519. The unused and undocumented ``django.utils.html.strip_entities()`` function has
  520. also been deprecated.