Release Notes
...
from tzlocal import get_localzone TIME_ZONE = get_localzone().zone
This works similar to settings.TIME_ZONE = None
except that it also sets os.environ['TZ']
. Let us know if there’s a use case where you find you can’t adapt your code to set a TIME_ZONE
.
...
- If no items in the feed have a
pubdate
orupdateddate
attribute,SyndicationFeed.latest_post_date()
now returns the current UTC date/time, instead of a datetime without any timezone information. - CSRF failures are logged to the
django.security.csrf
logger instead ofdjango.request
.Jira Legacy showSummary false server JIRA (openedx.atlassian.net) serverId 13fd1930-5608-3aac-a5dd-21b934d3a4b4 key PLAT-1381 ALLOWED_HOSTS
validation is no longer disabled when running tests.
If your application includes tests with custom host names, you must include those host names inJira Legacy showSummary false server JIRA (openedx.atlassian.net) serverId 13fd1930-5608-3aac-a5dd-21b934d3a4b4 key PLAT-1382 ALLOWED_HOSTS
. See Tests and multiple host names.- Using a foreign key’s id (e.g.
'field_id'
) inModelAdmin.list_display
displays the related object’s ID.
Remove theJira Legacy showSummary false server JIRA (openedx.atlassian.net) serverId 13fd1930-5608-3aac-a5dd-21b934d3a4b4 key PLAT-1383 _id
suffix if you want the old behavior of the string representation of the object. - In model forms,
CharField
withnull=True
now savesNULL
for blank values instead of empty strings.Jira Legacy showSummary false server JIRA (openedx.atlassian.net) serverId 13fd1930-5608-3aac-a5dd-21b934d3a4b4 key PLAT-1385 - On Oracle,
Model.validate_unique()
no longer checks empty strings for uniqueness as the database interprets the value asNULL
. - If you subclass
AbstractUser
and overrideclean()
, be sure it callssuper()
.BaseUserManager.normalize_email()
is called in a newAbstractUser.clean()
method so that normalization is applied in cases like model form validation. EmailField
andURLField
no longer accept thestrip
keyword argument. Remove it because it doesn’t have an effect in older versions of Django as these fields always strip whitespace.- The
checked
andselected
attribute rendered by form widgets now uses HTML5 boolean syntax rather than XHTML’schecked='checked'
andselected='selected'
. RelatedManager.add()
,remove()
,clear()
, andset()
now clear theprefetch_related()
cache.- To prevent possible loss of saved settings,
setup_test_environment()
now raises an exception if called a second time before callingteardown_test_environment()
. - The undocumented
DateTimeAwareJSONEncoder
alias forDjangoJSONEncoder
(renamed in Django 1.0) is removed. - The
cached template loader
is now enabled ifDEBUG
isFalse
andOPTIONS['loaders']
isn’t specified. This could be backwards-incompatible if you have some template tags that aren’t thread safe. - The prompt for stale content type deletion no longer occurs after running the
migrate
command. Use the newremove_stale_contenttypes
command instead. - The admin’s widget for
IntegerField
usestype="number"
rather thantype="text"
. - Conditional HTTP headers are now parsed and compared according to the RFC 7232 Conditional Requests specification rather than the older RFC 2616.
patch_response_headers()
no longer adds aLast-Modified
header. According to the RFC 7234#section-4.2.2, this header is useless alongside other caching headers that provide an explicit expiration time, e.g.Expires
orCache-Control
.UpdateCacheMiddleware
andadd_never_cache_headers()
callpatch_response_headers()
and therefore are also affected by this change.- In the admin templates,
<p class="help">
is replaced with a<div>
tag to allow including lists inside help text. ConditionalGetMiddleware
no longer sets theDate
header as Web servers set that header. It also no longer sets theContent-Length
header as this is now done byCommonMiddleware
.get_model()
andget_models()
now raiseAppRegistryNotReady
if they’re called before models of all applications have been loaded. Previously they only required the target application’s models to be loaded and thus could return models without all their relations set up. If you need the old behavior ofget_model()
, set therequire_ready
argument toFalse
.- The unused
BaseCommand.can_import_settings
attribute is removed. - The undocumented
django.utils.functional.lazy_property
is removed. - For consistency with non-multipart requests,
MultiPartParser.parse()
now leavesrequest.POST
immutable. If you’re modifying thatQueryDict
, you must now first copy it, e.g.request.POST.copy()
. - Support for
cx_Oracle
< 5.2 is removed. - Support for IPython < 1.0 is removed from the
shell
command. - The signature of private API
Widget.build_attrs()
changed fromextra_attrs=None, **kwargs
tobase_attrs,extra_attrs=None
. - File-like objects (e.g.,
StringIO
andBytesIO
) uploaded to anImageField
using the test client now require aname
attribute with a value that passes thevalidate_image_file_extension
validator. See the note inClient.post()
.
...
from django.db import models class MyModel(models.Model): ... @models.permalink def url(self): return ('guitarist_detail', [self.slug])
becomes:
from django.db import models from django.urls import reverse class MyModel(models.Model): ... def url(self): return reverse('guitarist_detail', args=[self.slug])
Miscellaneous¶
contrib.auth
’slogin()
andlogout()
function-based views are deprecated in favor of new class-based viewsLoginView
andLogoutView
.- The unused
extra_context
parameter ofcontrib.auth.views.logout_then_login()
is deprecated. contrib.auth
’spassword_change()
,password_change_done()
,password_reset()
,password_reset_done()
,password_reset_confirm()
, andpassword_reset_complete()
function-based views are deprecated in favor of new class-based viewsPasswordChangeView
,PasswordChangeDoneView
,PasswordResetView
,PasswordResetDoneView
,PasswordResetConfirmView
, andPasswordResetCompleteView
.django.test.runner.setup_databases()
is moved todjango.test.utils.setup_databases()
. The old location is deprecated.django.utils.translation.string_concat()
is deprecated in favor ofdjango.utils.text.format_lazy()
.string_concat(*strings)
can be replaced byformat_lazy('{}' * len(strings), *strings)
.- For the
PyLibMCCache
cache backend, passingpylibmc
behavior settings as top-level attributes ofOPTIONS
is deprecated. Set them under abehaviors
key withinOPTIONS
instead. - The
host
parameter ofdjango.utils.http.is_safe_url()
is deprecated in favor of the newallowed_hosts
parameter. - Silencing exceptions raised while rendering the
{% include %}
template tag is deprecated as the behavior is often more confusing than helpful. In Django 2.1, the exception will be raised. DatabaseIntrospection.get_indexes()
is deprecated in favor ofDatabaseIntrospection.get_constraints()
.authenticate()
now passes arequest
argument to theauthenticate()
method of authentication backends. Support for methods that don’t acceptrequest
as the first positional argument will be removed in Django 2.1.- The
USE_ETAGS
setting is deprecated in favor ofConditionalGetMiddleware
which now adds theETag
header to responses regardless of the setting.CommonMiddleware
anddjango.utils.cache.patch_response_headers()
will no longer set ETags when the deprecation ends. Model._meta.has_auto_field
is deprecated in favor of checking ifModel._meta.auto_field is not None
.- Using regular expression groups with
iLmsu#
inurl()
is deprecated. The only group that’s useful is(?i)
for case-insensitive URLs, however, case-insensitive URLs aren’t a good practice because they create multiple entries for search engines, for example. An alternative solution could be to create ahandler404
that looks for uppercase characters in the URL and redirects to a lowercase equivalent. - The
renderer
argument is added to theWidget.render()
method. Methods that don’t accept that argument will work through a deprecation period.