1.8.txt 26 KB

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