Django 1.11 リリースノート¶
April 4, 2017
Django 1.11 へようこそ!
このリリースノートでは、Django 1.10 および過去のバージョンからアップグレードする際に知っておくべきいくつかの 後方互換性のない変更 に加え、新機能 を説明しています。いくつかの機能に対する廃止プロセスを開始しました。
既存のプロジェクトをアップデートするときは、 Django の新しいバージョンへの更新 ガイドに従ってください。
Django 1.11 is designated as a long-term support release. It will receive security updates for at least three years after its release. Support for the previous LTS, Django 1.8, will end in April 2018.
Python バージョン間の互換性¶
Django 1.11 の動作には Python 2.7, 3.4, 3.5, 3.6, 3.7 のいずれかが必要です。各バージョン系列の最終リリースの Python を使用することを 強く推奨 し、公式には最終リリースしかサポートしません。
The Django 1.11.x series is the last to support Python 2. The next major release, Django 2.0, will only support Python 3.4+.
廃止予定警告はデフォルトでは表示されなくなりました。¶
Django の過去のバージョンとは異なり、Django 自体の廃止予定警告はデフォルトでは非表示となりました。これは Python のデフォルト動作と同じです。
これによって、サードパーティアプリが、廃止予定警告を回避するためのコードを追加することなく、Django 1.11 LTS と Django 1.8 LTS の両方をサポートできるようになります。
Django 2.0 のリリースを控えているため、サードパーティアプリの開発者は 1.11 以前のバージョンの Django へのサポートを終えるよう推奨します。このとき、python -Wd
を使ったパッケージテストを実行できるようにして、廃止予定警告を表示します。廃止予定警告を作り終えたら、アプリケーションは Django 2.0 と互換可能となります。
What's new in Django 1.11¶
クラスベースモデルのインデックス¶
新しい django.db.models.indexes
モジュールはデータベースインデックスの作成を簡単にするクラスを含んでいます。インデックスは Meta.indexes
オプションを使ってモデルに追加されます。
The Index
class creates a b-tree index, as if you
used db_index
on the model field or
index_together
on the model Meta
class.
It can be subclassed to support different index types, such as
GinIndex
. It also allows defining the
order (ASC/DESC) for the columns of the index.
テンプレートベースのウィジェット表示¶
ウィジェットのカスタマイズを簡単にするため、フォームウィジェットの表示が Python 内ではなくテンプレートシステムを使って行われるようになりました。フォームレンダリング API を参照してください。
いくつかの 後方互換性のない変更 のため、実装済みのカスタムウィジェットを調整する必要があるかもしれません。
Subquery
表現¶
新たな Subquery
と Exists
データベース表現によって、明示的なサブクエリを作成することができます。サブクエリは、OuterRef
を使って外部のクエリセットからフィールドを参照することができます。
マイナーな機能¶
django.contrib.admin
¶
ModelAdmin.date_hierarchy
はリレーションシップを通じてフィールドを参照できるようになりました。- 新たな
ModelAdmin.get_exclude()
フックによって、リクエストやモデルインスタンスに基づいた除外フィールドを指定できます。 popup_response.html
テンプレートが、アプリケーションごと、モデルごと、もしくはセッティングModelAdmin.popup_response_template
属性によってオーバーライドできるようになりました。
django.contrib.auth
¶
- PBKDF2 パスワードハッシュに対するデフォルトのイテレーションカウントが 20% 増加しました。
LoginView
とLogoutView
クラスベースビューが、廃止されるlogin()
とlogout()
関数ベースビューの後継となりました。PasswordChangeView
、PasswordChangeDoneView
、PasswordResetView
、PasswordResetDoneView
、PasswordResetConfirmView
、PasswordResetCompleteView
クラスベースビューが、廃止されるpassword_change()
、password_change_done()
、password_reset()
、password_reset_done()
、password_reset_confirm()
、password_reset_complete()
関数ビューの後継となりました。PasswordResetConfirmView
の新しいpost_reset_login
属性によって、パスワードリセットが成功した後に自動的にログインできるようになりました。複数のAUTHENTICATION_BACKENDS
を設定している場合、post_reset_login_backend
属性を使ってどれを使うか選択してください。- HTTP リファラヘッダを通じてパスワードリセットトークンが漏れる可能性を防ぐため (たとえば、リセットページが他のドメインにホストされた CSS や JavaScript への参照を含む場合)、
PasswordResetConfirmView
(廃止されるpassword_reset_confirm()
関数ベースビューではありません) セッションにトークンを保持し、自身にリダイレクトして URL 内のトークンなしでユーザへのパスワード変更フォームを送信します。 update_session_auth_hash()
がセッションキーをローテーションさせるようになり、パスワード変更が盗聴されたセッションクッキーを無効化できるようになりました。LoginView
とLogoutView
の新しいsuccess_url_allowed_hosts
属性によって、ログインおよびログアウト後のリダイレクトに対して安全なホストのセットを指定できるようになりました。- パスワードのバリデータ
help_text
がUserCreationForm
に追加されました。 HttpRequest
がauthenticate()
に渡されるようになりました。これは、request
属性を受け入れる場合にリクエストを認証バックエンドに順番に渡します。user_login_failed()
シグナルがrequest
属性を受け取るようになりました。PasswordResetForm
は'email'
ではない名前の E メールフィールドを使うカスタムユーザーモデルをサポートします。CustomUser.EMAIL_FIELD
をフィールドの名前にセットしてください。- モデルを定義するモジュール内においても、
get_user_model()
をインポート時に呼ぶことができるようになりました。
django.contrib.contenttypes
¶
- When stale content types are detected in the
remove_stale_contenttypes
command, there's now a list of related objects such asauth.Permission
s that will also be deleted. Previously, only the content types were listed (and this prompt was aftermigrate
rather than in a separate command).
django.contrib.gis
¶
- 新たな
GEOSGeometry.from_gml()
とOGRGeometry.from_gml()
メソッドによって、GML から幾何学的配置を作成できるようになりました。 - Added support for the
dwithin
lookup on SpatiaLite. - The
Area
function,Distance
function, and distance lookups now work with geodetic coordinates on SpatiaLite. - The OpenLayers-based form widgets now use
OpenLayers.js
fromhttps://cdnjs.cloudflare.com
which is more suitable for production use than the oldhttps://openlayers.org/
source. They are also updated to use OpenLayers 3. - PostGIS migrations can now change field dimensions.
- Added the ability to pass the
size
,shape
, andoffset
parameters when creatingGDALRaster
objects. - Added SpatiaLite support for the
IsValid
function,MakeValid
function, andisvalid
lookup. - Added Oracle support for the
AsGML
function,BoundingCircle
function,IsValid
function, andisvalid
lookup.
django.contrib.postgres
¶
- The new
distinct
argument forStringAgg
determines if concatenated values will be distinct. - The new
GinIndex
andBrinIndex
classes allow creatingGIN
andBRIN
indexes in the database. django.contrib.postgres.fields.JSONField
accepts a newencoder
parameter to specify a custom class to encode data types not supported by the standard encoder.- The new
CIText
mixin andCITextExtension
migration operation allow using PostgreSQL'scitext
extension for case-insensitive lookups. Three fields are provided:CICharField
,CIEmailField
, andCITextField
. - The new
JSONBAgg
allows aggregating values as a JSON array. - The
HStoreField
(model field) andHStoreField
(form field) allow storing null values.
キャッシュ¶
- Memcached backends now pass the contents of
OPTIONS
as keyword arguments to the client constructors, allowing for more advanced control of client behavior. See the cache arguments documentation for examples. - Memcached backends now allow defining multiple servers as a comma-delimited
string in
LOCATION
, for convenience with third-party services that use such strings in environment variables.
CSRF¶
- Added the
CSRF_USE_SESSIONS
setting to allow storing the CSRF token in the user's session rather than in a cookie.
データベースバックエンド¶
- Added the
skip_locked
argument toQuerySet.select_for_update()
on PostgreSQL 9.5+ and Oracle to execute queries withFOR UPDATE SKIP LOCKED
. - Added the
TEST['TEMPLATE']
setting to let PostgreSQL users specify a template for creating the test database. QuerySet.iterator()
now uses server-side cursors on PostgreSQL. This feature transfers some of the worker memory load (used to hold query results) to the database and might increase database memory usage.- Added MySQL support for the
'isolation_level'
option inOPTIONS
to allow specifying the transaction isolation level. To avoid possible data loss, it's recommended to switch from MySQL's default level, repeatable read, to read committed. - Added support for
cx_Oracle
5.3.
E メール¶
EMAIL_USE_LOCALTIME
設定が追加され、SMTP 日付ヘッダを UTC ではなくローカルタイムゾーンで送信できるようになりました。EmailMessage.attach()
andattach_file()
now fall back to MIME type application/octet-stream when binary content that can't be decoded as UTF-8 is specified for a text/* attachment.
ファイルストレージ¶
io.TextIOWrapper
でラップできるように、File
にreadable()
、writable()
、seekable()
メソッドが追加されました。
フォーム¶
- The new
empty_value
attribute onCharField
,EmailField
,RegexField
,SlugField
, andURLField
allows specifying the Python value to use to represent "empty". - 新たな
Form.get_initial_for_field()
メソッドは、フォームフィールドに対する初期データを返します。
国際化 (internationalization)¶
- 数値の書式および
NUMBER_GROUPING
設定が単一ではない桁グルーピングをサポートするようになりました。
管理コマンド¶
- 新たな
loaddata --exclude
オプションによって、フィクスチャからデータを読み込んでいる間にモデルとアプリケーションを除外することができるようになりました。 - 新たな
diffsettings --default
オプションによって、Django のデフォルトの設定以外の設定モジュールを指定し、対比できるようになりました。 app_label
属性がshowmigrations --plan
アウトプットを制限するようになりました。
マイグレーション¶
uuid.UUID
オブジェクトのシリアライズに対するサポートを追加しました。
モデル¶
QuerySet.update_or_create()
とget_or_create()
のdefaults
属性で呼び出し可能な値に対するサポートが追加されました。ImageField
now has a defaultvalidate_image_file_extension
validator. (This validator moved to the form field in Django 1.11.2.)- Added support for time truncation to
Trunc
functions. - Added the
ExtractWeek
function to extract the week fromDateField
andDateTimeField
and exposed it through theweek
lookup. - Added the
TruncTime
function to truncateDateTimeField
to its time component and exposed it through thetime
lookup. QuerySet.values()
とvalues_list()
の表現へのサポートを追加しました。range
のような複数属性を取るルックアップでのクエリ表現へのサポートを追加しました。FileField
でunique=True
オプションを使用できるようになりました。nulls_first
とnulls_last
パラメータをExpression.asc()
とdesc()
に追加し、null 値の順序をコントロールできるようにしました。- 新たな
F
表現bitleftshift()
とbitrightshift()
メソッドによって、ビットワイズシフトオペレーション ができるようになりました。 QuerySet.union()
、intersection()
、difference()
を追加しました。
Request と Response¶
QueryDict.fromkeys()
を追加しました。CommonMiddleware
が 非ストリーミングレスポンスに対してContent-Length
レスポンスヘッダをセットするようになりました。- Added the
SECURE_HSTS_PRELOAD
setting to allow appending thepreload
directive to theStrict-Transport-Security
header. ConditionalGetMiddleware
now adds theETag
header to responses.
シリアライズ (シリアル化)¶
- The new
django.core.serializers.base.Serializer.stream_class
attribute allows subclasses to customize the default stream. - The encoder used by the JSON serializer
can now be customized by passing a
cls
keyword argument to theserializers.serialize()
function. DjangoJSONEncoder
now serializestimedelta
objects (used byDurationField
).
テンプレート¶
mark_safe()
can now be used as a decorator.- The
Jinja2
template backend now supports context processors by setting the'context_processors'
option inOPTIONS
. - The
regroup
tag now returnsnamedtuple
s instead of dictionaries so you can unpack the group object directly in a loop, e.g.{% for grouper, list in regrouped %}
. - Added a
resetcycle
template tag to allow resetting the sequence of thecycle
template tag. - You can now specify specific directories for a particular
filesystem.Loader
.
テスト¶
- Added
DiscoverRunner.get_test_runner_kwargs()
to allow customizing the keyword arguments passed to the test runner. - Added the
test --debug-mode
option to help troubleshoot test failures by setting theDEBUG
setting toTrue
. - The new
django.test.utils.setup_databases()
(moved fromdjango.test.runner
) andteardown_databases()
functions make it easier to build custom test runners. - Added support for
unittest.TestCase.subTest()
’s when using thetest --parallel
option. DiscoverRunner
now runs the system checks at the start of a test run. Override theDiscoverRunner.run_checks()
method if you want to disable that.
バリデータ¶
- ファイル拡張子を検証する
FileExtensionValidator
と、 画像ファイルを検証するvalidate_image_file_extension
を追加しました。
1.11 における後方互換性のない変更¶
django.contrib.gis
¶
- To simplify the codebase and because it's easier to install than when
contrib.gis
was first released, GDAL is now a required dependency for GeoDjango. In older versions, it's only required for SQLite. contrib.gis.maps
is removed as it interfaces with a retired version of the Google Maps API and seems to be unmaintained. If you're using it, let us know.- The
GEOSGeometry
equality operator now also compares SRID. - The OpenLayers-based form widgets now use OpenLayers 3, and the
gis/openlayers.html
andgis/openlayers-osm.html
templates have been updated. Check your project if you subclass these widgets or extend the templates. Also, the new widgets work a bit differently than the old ones. Instead of using a toolbar in the widget, you click to draw, click and drag to move the map, and click and drag a point/vertex/corner to move it. - Support for SpatiaLite < 4.0 is dropped.
- Support for GDAL 1.7 and 1.8 is dropped.
- The widgets in
contrib.gis.forms.widgets
and the admin'sOpenLayersWidget
use the form rendering API rather thanloader.render_to_string()
. If you're using a custom widget template, you'll need to be sure your form renderer can locate it. For example, you could use theTemplatesSetting
renderer.
django.contrib.staticfiles
¶
collectstatic
may now fail during post-processing when using a hashed static files storage if a reference loop exists (e.g.'foo.css'
references'bar.css'
which itself references'foo.css'
) or if the chain of files referencing other files is too deep to resolve in several passes. In the latter case, increase the number of passes usingManifestStaticFilesStorage.max_post_process_passes
.- When using
ManifestStaticFilesStorage
, static files not found in the manifest at runtime now raise aValueError
instead of returning an unchanged path. You can revert to the old behavior by settingManifestStaticFilesStorage.manifest_strict
toFalse
.
データベースバックエンド API¶
このセクションでは、サードパーティのデータベースバックエンドで必要になる可能性のある変更について説明します。
- The
DatabaseOperations.time_trunc_sql()
method is added to supportTimeField
truncation. It accepts alookup_type
andfield_name
arguments and returns the appropriate SQL to truncate the given time fieldfield_name
to a time object with only the given specificity. Thelookup_type
argument can be either'hour'
,'minute'
, or'second'
. - The
DatabaseOperations.datetime_cast_time_sql()
method is added to support thetime
lookup. It accepts afield_name
andtzname
arguments and returns the SQL necessary to cast a datetime value to time value. - To enable
FOR UPDATE SKIP LOCKED
support, setDatabaseFeatures.has_select_for_update_skip_locked = True
. - The new
DatabaseFeatures.supports_index_column_ordering
attribute specifies if a database allows defining ordering for columns in indexes. The default value isTrue
and theDatabaseIntrospection.get_constraints()
method should include an'orders'
key in each of the returned dictionaries with a list of'ASC'
and/or'DESC'
values corresponding to the ordering of each column in the index. inspectdb
no longer callsDatabaseIntrospection.get_indexes()
which is deprecated. Custom database backends should ensure all types of indexes are returned byDatabaseIntrospection.get_constraints()
.- Renamed the
ignores_quoted_identifier_case
feature toignores_table_name_case
to more accurately reflect how it is used. - The
name
keyword argument is added to theDatabaseWrapper.create_cursor(self, name=None)
method to allow usage of server-side cursors on backends that support it.
Dropped support for PostgreSQL 9.2 and PostGIS 2.0¶
Upstream support for PostgreSQL 9.2 ends in September 2017. As a consequence, Django 1.11 sets PostgreSQL 9.3 as the minimum version it officially supports.
Support for PostGIS 2.0 is also removed as PostgreSQL 9.2 is the last version to support it.
Also, the minimum supported version of psycopg2 is increased from 2.4.5 to 2.5.4.
LiveServerTestCase
binds to port zero¶
Rather than taking a port range and iterating to find a free port,
LiveServerTestCase
binds to port zero and relies on the operating system
to assign a free port. The DJANGO_LIVE_TEST_SERVER_ADDRESS
environment
variable is no longer used, and as it's also no longer used, the
manage.py test --liveserver
option is removed.
If you need to bind LiveServerTestCase
to a specific port, use the port
attribute added in Django 1.11.2.
django.contrib.auth
や i18n
ビューでの安全でないリダイレクトに対する保護¶
LoginView
、LogoutView
(廃止される関数ベースのビュー) および set_language()
は、アプリケーションが HTTPS で動作しているとき、非 HTTPS の next
URL へのリダイレクトからユーザを保護します。
QuerySet.get_or_create()
と update_or_create()
の引数の検証¶
警告なしに引数を渡すことでタイポが発生するのを防ぐため、get_or_create()
と update_or_create()
が、引数がモデルフィールドかどうかをチェックするようになりました。これはプロジェクト内のバグを顕在化するので、後方互換性がないと言えます。
pytz
は必須の依存となり、settings.TIME_ZONE = None
のサポートは削除されました。¶
Django のタイムゾーン処理をシンプルにするため、pytz
が必須の依存となりました。Django とともに自動的にインストールされます。
settings.TIME_ZONE = None
のサポートは削除されました、この動作は一般的に使用されておらず、有用性に疑問があるためです。システムのタイムゾーンに基づいて自動的にタイムゾーンを検出したい場合は、 tzlocal: が使用できます:
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
.
admin テンプレート内の HTML の変更¶
<p class="help">
が <div>
タグに置き換えられ、ヘルプテキスト内にリストを含められるようになりました。
読み取り専用のフィールドが <p>...</p>
ではなく <div class="readonly">...</div>
でラップされるようになり、どんな種類の HTML でもフィールドのコンテンツとして使えるようになりました。
テンプレートベースのウィジェットレンダリングの導入による変更¶
django.forms.widgets
内の、ドキュメント化されていないいくつかのクラスが削除されました:
SubWidget
RendererMixin
、ChoiceFieldRenderer
、RadioFieldRenderer
、CheckboxFieldRenderer
ChoiceInput
、RadioChoiceInput
、CheckboxChoiceInput
The undocumented Select.render_option()
method is removed.
Widget.format_output()
メソッドは削除されました。代わりにカスタムウィジェットテンプレートを使用してください。
いくつかのウィジェット値 (たとえば <select>
オプション) が、settings.USE_L10N=True
の場合にローカル化されるようになりました。ローカル化を無効にする localize
テンプレートタグを使ったカスタムウィジェットテンプレートを使用すれば、旧来の動作に戻すことができます。
django.template.backends.django.Template.render()
prohibits non-dict context¶
For compatibility with multiple template engines,
django.template.backends.django.Template.render()
(returned from high-level
template loader APIs such as loader.get_template()
) must receive a
dictionary of context rather than Context
or RequestContext
. If you
were passing either of the two classes, pass a dictionary instead -- doing so
is backwards-compatible with older versions of Django.
マイグレーション処理でのモデル状態の変更¶
マイグレーション適用のスピードを改善するため、処理が必要とするまで関連モデルのレンダリングを送らせるようになりました (例: RunPython
)。database_forwards()
や database_backwards()
の from_state
引数からモデルクラスやモデルインスタンスを操作するような独自の処理を作成していた場合、独自のマイグレーション処理を記述する で説明しているように、clear_delayed_apps_cache()
メソッドを使ってモデル状態をレンダリングする必要があります。
Server-side cursors on PostgreSQL¶
The change to make QuerySet.iterator()
use server-side cursors on
PostgreSQL prevents running Django with PgBouncer in transaction pooling mode.
To reallow that, use the DISABLE_SERVER_SIDE_CURSORS
setting (added in Django 1.11.1) in
DATABASES
.
See トランザクションプールとサーバーサイドカーソル for more discussion.
その他¶
フィードのアイテムが
pubdate
やupdateddate
属性を持たない場合、SyndicationFeed.latest_post_date()
がタイムゾーン情報を持たない日時ではなく現在の UTC 日/時を返すようになりました。CSRF の失敗が
django.request
ではなくdjango.security.csrf
ロガーに記録されるようになりました。ALLOWED_HOSTS
バリデーションが、テスト時に無効化されないようになりました。アプリケーションが独自のホスト名でのテストを含む場合、そのホスト名をALLOWED_HOSTS
に含める必要があります。テストとマルチホスト名 を参照してください。ModelAdmin.list_display
で外部キーの ID (e.g.'field_id'
) を使用すると関連オブジェクトの ID を表示するようになりました。旧来の動作であるオブジェクトの文字列表現を使いたい場合は、_id
サフィックスを削除してください。モデルフォーム内で、
null=True
のCharField
が、ブランク値に対して空の文字列ではなくNULL
を保存するようになりました。Oracleでは、データベースが値を
NULL
として解釈するため、Model.validate_unique()
が一意性に対する空の文字列をチェックしなくなりました。AbstractUser
をサブクラス化してclean()
をオーバーライドする場合、super()
を呼ぶようにしてください。モデルフォームバリデーションのような場合に標準化が適用されるよう、新たなAbstractUser.clean()
メソッド内でBaseUserManager.normalize_email()
が呼ばれます。EmailField
とURLField
が キーワード引数strip
を受け付けなくなりました。受け付けなくなった理由は、古いバージョンのDjangoでは、常に空白を取り除いており、効果がないからです。フォームウィジェットでレンダリングされる
checked
とselected
属性が、XHTML のchecked='checked'
やselected='selected'
ではなく HTML5 ブール値シンタックスを使用するようになりました。RelatedManager.add()
、remove()
、clear()
、set()
がprefetch_related()
キャッシュをクリアするようになりました。保存した値を失わないように、
teardown_test_environment()
を呼び出す前に 2 度めの呼び出しをした場合、setup_test_environment()
がエラーを投げるようになりました。DjangoJSONEncoder
(Django 1.0 でリネームされました) に対する、ドキュメント化していないDateTimeAwareJSONEncoder
エイリアスが削除されました。The
cached template loader
is now enabled ifOPTIONS['loaders']
isn't specified andOPTIONS['debug']
isFalse
(the latter option defaults to the value ofDEBUG
). This could be backwards-incompatible if you have some template tags that aren't thread safe.古いコンテンツタイプ削除のプロンプトが、
migrate
コマンド後に表示されなくなりました。代わりに、新たなremove_stale_contenttypes
コマンドを使用してください。IntegerField
に対する admin のウィジェットがtype="text"
ではなくtype="number"
を使うようになりました。条件付き HTTP ヘッダが、古い RFC 2616 ではなく RFC 7232 条件付きリクエストの仕様によって解析および比較されるようになりました。
patch_response_headers()
がLast-Modified
ヘッダを追加しないようになりました。RFC 7234#section-4.2.2 によると、明示的な有効期限を提供する他のキャッシングヘッダ (たとえばExpires
やCache-Control
) とともに無用となりました。UpdateCacheMiddleware
およびadd_never_cache_headers()
はpatch_response_headers()
を呼び出すため、この変更の影響を受けます。admin テンプレート内で、
<p class="help">
が<div>
タグに置き換えられ、ヘルプテキスト内にリストを含められるようになりました。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
.If you have a middleware that modifies a response's content and appears before
CommonMiddleware
in theMIDDLEWARE
orMIDDLEWARE_CLASSES
settings, you must reorder your middleware so that responses aren't modified afterContent-Length
is set, or have the response modifying middleware reset theContent-Length
header.すべてのアプリケーションのモデルが読み込まれる前に呼び出された場合、
get_model()
およびget_models()
がAppRegistryNotReady
を投げるようになりました。以前は対象のアプリケーションのモデルが読み込まれることのみが必須で、リレーションシップのセットアップなしでモデルを返すことができました。get_model()
の旧来の動作が必要な場合は、require_ready
引数をFalse
にセットしてください。無用な
BaseCommand.can_import_settings
属性が削除されました。ドキュメント化されていなかった
django.utils.functional.lazy_property
が削除されました。非マルチパートのリクエストとの整合性のため、
MultiPartParser.parse()
がrequest.POST
を不変のままにするようになりました。したがってこのQueryDict
を修正する場合は、まずコピーする必要があります (例:request.POST.copy()
)。cx_Oracle
5.2 未満へのサポートが削除されました。IPython 1.0 未満へのサポートが
shell
コマンドから削除されました。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()
.FileField
now moves rather than copies the file it receives. With the default file upload settings, files larger thanFILE_UPLOAD_MAX_MEMORY_SIZE
now have the same permissions as temporary files (often0o600
) rather than the system's standard umask (often0o6644
). Set theFILE_UPLOAD_PERMISSIONS
if you need the same permission regardless of file size.
1.11 で非推奨となった機能¶
models.permalink()
デコレータ¶
代わりに django.urls.reverse()
を使用してください。例えば:
from django.db import models
class MyModel(models.Model):
...
@models.permalink
def url(self):
return ("guitarist_detail", [self.slug])
は、以下のようになります:
from django.db import models
from django.urls import reverse
class MyModel(models.Model):
...
def url(self):
return reverse("guitarist_detail", args=[self.slug])
その他¶
- 新たなクラスベースビュー
LoginView
とLogoutView
が採用されたため、contrib.auth
のlogin()
およびlogout()
関数ベースビューは非推奨となりました。 contrib.auth.views.logout_then_login()
の無用のextra_context
パラメータが非推奨となりました。- 新たなクラスベースビュー
PasswordChangeView
、PasswordChangeDoneView
、PasswordResetView
、PasswordResetDoneView
、PasswordResetConfirmView
、PasswordResetCompleteView
が採用されたため、contrib.auth
のpassword_change()
、password_change_done()
、password_reset()
、password_reset_done()
、password_reset_confirm()
、password_reset_complete()
は非推奨となりました。 django.test.runner.setup_databases()
がdjango.test.utils.setup_databases()
に移動しました。旧来の場所は非推奨となります。django.utils.text.format_lazy()
が採用されたため、django.utils.translation.string_concat()
は非推奨となりました。string_concat(*strings)
はformat_lazy('{}' * len(strings), *strings)
で置き換えることができます。PyLibMCCache
キャッシュバックエンドに対して、pylibmc
動作設定をOPTIONS
のトップレベル属性として渡すことは非推奨となりました。代わりに、OPTIONS
内のbehaviors
キー下にセットしてください。- 新たな
allowed_hosts
が採用されたため、django.utils.http.is_safe_url()
のhost
は非推奨となりました。 - 有用性よりも混乱の原因になることが多いため、
{% include %}
テンプレートタグをレンダリングするときに投げられる例外を無効化することは非推奨となりました。Django 2.1 で、この例外は投げられるようになります。 DatabaseIntrospection.get_constraints()
が採用されたため、DatabaseIntrospection.get_indexes()
は非推奨となりました。authenticate()
が認証バックエンドのauthenticate()
メソッドにrequest
引数を渡すようになりました。request
を第 1 省略可能引数として受け取らないメソッドへのサポートは Django 2.1 で削除されます。- 設定にかかわらず
ETag
ヘッダをレスポンスに追加するようになったConditionalGetMiddleware
が採用されたため、USE_ETAGS
設定は非推奨となりました。CommonMiddleware
およびdjango.utils.cache.patch_response_headers()
は非推奨が終了するときに ETags をセットしなくなります。 Model._meta.auto_field が None かどうか
をチェックする方法が採用されたので、Model._meta.has_auto_field
は非推奨となりました。url()
内でiLmsu#
で正規表現グループを使用することは非推奨となりました。大文字と小文字を区別しない URL に対して有用なグループは(?i)
のみとなりますが、大文字と小文字を区別しない URL は、たとえば検索エンジン用に複数のエントリを作成するため、適切ではありません。 代わりの解決方法として、URL 内で大文字を検索して小文字の同等の URL にリダイレクトするようなhandler404
を作成する方法があります。Widget.render()
メソッドにrenderer
引数が追加されました。廃止されるまでは、この引数を受け取らないメソッドも動作します。