... django.views.decorators.http にある以下のデコレータを使って、特定のビューのキャッシュ動作を制御できます。 condition ( etag_func = None , last_modified_func = None ) [ソース] ¶ conditional_page () ¶ このデコレータを使用すると、ビューに ConditionalGetM ... iddleware と同等の条件付き GET 処理を追加できます。 etag ( etag_func ) [ソース] ¶ last_modified ( last_modified_func ) [ソース] ¶ これらのデコレータは ETag と Last-Modified ヘッダを生成するた ... go.views.decorators.vary のデコレータを使って、特定のリクエストヘッダに基づいてキャッシュを制御できます。 vary_on_cookie ( func ) ¶ vary_on_headers ( * headers ) [ソース] ¶ Vary ヘッダーはキャッシュメカニズムがキャッシュキーを構築するときにどのリクエ ... ... django.views.decorators.http にある以下のデコレータを使って、特定のビューのキャッシュ動作を制御できます。 condition ( etag_func = None , last_modified_func = None ) [ソース] ¶ conditional_page () ¶ このデコレータを使用すると、ビューに ConditionalGetM ... iddleware と同等の条件付き GET 処理を追加できます。 etag ( etag_func ) [ソース] ¶ last_modified ( last_modified_func ) [ソース] ¶ これらのデコレータは ETag と Last-Modified ヘッダを生成するた ... go.views.decorators.vary のデコレータを使って、特定のリクエストヘッダに基づいてキャッシュを制御できます。 vary_on_cookie ( func ) ¶ vary_on_headers ( * headers ) [ソース] ¶ Vary ヘッダーはキャッシュメカニズムがキャッシュキーを構築するときにどのリクエ ... ... の新しいコピーを計算して通常のビューを呼び出します。 condition デコレータのシグネチャは次のようになります。 condition ( etag_func = None , last_modified_func = None ) ETag と最終更新時間を計算するための2つの関数は、受信した request オブジェクトと、それ ... らがサポートするビュー関数と同じパラメータを、同じ順序で渡されます。 last_modified_func に渡された関数は、リソースが最後に変更された時間を指定する標準の datetime 値を返すべきです。または、リソースが存在しない場 ... で変更されていないページを早期に検出できます。 from django.views.decorators.http import condition @condition ( last_modified_func = latest_entry ) def front_page ( request , blog_id ): ... デコレータの順番に注意 条件付きレスポンスが condition() によって ... ... の新しいコピーを計算して通常のビューを呼び出します。 condition デコレータのシグネチャは次のようになります。 condition ( etag_func = None , last_modified_func = None ) ETag と最終更新時間を計算するための2つの関数は、受信した request オブジェクトと、それ ... らがサポートするビュー関数と同じパラメータを、同じ順序で渡されます。 last_modified_func に渡された関数は、リソースが最後に変更された時間を指定する標準の datetime 値を返すべきです。または、リソースが存在しない場 ... で変更されていないページを早期に検出できます。 from django.views.decorators.http import condition @condition ( last_modified_func = latest_entry ) def front_page ( request , blog_id ): ... デコレータの順番に注意 条件付きレスポンスが condition() によって ... ... フィールドを作成する を参照してください。 例 ¶ >>> from django.db.models import Count , F , Value >>> from django.db.models.functions import Length , Upper >>> from django.db.models.lookups import GreaterThan # Find companies that have more employees ... c ()) # or using the double underscore lookup syntax. >>> from django.db.models import CharField >>> from django.db.models.functions import Length >>> CharField . register_lookup ( Length ) >>> Company . objects . order_by ( "name__length" ) # Boolea ... 転する場合、以下のようにします: from django.db.models import F Company . objects . update ( is_active =~ F ( "is_active" )) Func() 式 ¶ Func() 式は COALESCE や LOWER のようなデータベース関数や、 SUM のような集計を含むすべての式の基本型です。これらは直 ... ... フィールドを作成する を参照してください。 例 ¶ >>> from django.db.models import Count , F , Value >>> from django.db.models.functions import Length , Upper >>> from django.db.models.lookups import GreaterThan # Find companies that have more employees ... c ()) # or using the double underscore lookup syntax. >>> from django.db.models import CharField >>> from django.db.models.functions import Length >>> CharField . register_lookup ( Length ) >>> Company . objects . order_by ( "name__length" ) # Boolea ... 転する場合、以下のようにします: from django.db.models import F Company . objects . update ( is_active =~ F ( "is_active" )) Func() 式 ¶ Func() 式は COALESCE や LOWER のようなデータベース関数や、 SUM のような集計を含むすべての式の基本型です。これらは直 ... ... RunPython を用いて Country モデル上の初期オブジェクトを追加する例を示します: from django.db import migrations def forwards_func ( apps , schema_editor ): # We get the model from the versioned app registry; # if we directly import it, it'll be the wro ... ias ) . bulk_create ( [ Country ( name = "USA" , code = "us" ), Country ( name = "France" , code = "fr" ), ] ) def reverse_func ( apps , schema_editor ): # forwards_func() creates two Country instances, # so reverse_func() should delete them. Country ... . delete () class Migration ( migrations . Migration ): dependencies = [] operations = [ migrations . RunPython ( forwards_func , reverse_func ), ] これは データのマイグレーション の作成、独自のデータ更新と構成変更、そして ORM や Python のコードにアク ... ... tructure is later changed with JavaScript. For instance, when binding a click handler, use $('body').on('click', selector, func) instead of $(selector).click(func) . This makes it easier for projects to extend Django's default behavior with JavaScrip ... 書く ¶ Django's JavaScript tests use QUnit . Here is an example test module: QUnit . module ( 'magicTricks' , { beforeEach : function () { const $ = django . jQuery ; $ ( '#qunit-fixture' ). append ( '<button class="button"></button>' ); } }); QUnit . ... test ( 'removeOnClick removes button on click' , function ( assert ) { const $ = django . jQuery ; removeOnClick ( '.button' ); assert . equal ( $ ( '.button' ). length , 1 ); ... ... RunPython を用いて Country モデル上の初期オブジェクトを追加する例を示します: from django.db import migrations def forwards_func ( apps , schema_editor ): # We get the model from the versioned app registry; # if we directly import it, it'll be the wro ... ias ) . bulk_create ( [ Country ( name = "USA" , code = "us" ), Country ( name = "France" , code = "fr" ), ] ) def reverse_func ( apps , schema_editor ): # forwards_func() creates two Country instances, # so reverse_func() should delete them. Country ... . delete () class Migration ( migrations . Migration ): dependencies = [] operations = [ migrations . RunPython ( forwards_func , reverse_func ), ] これは データのマイグレーション の作成、独自のデータ更新と構成変更、そして ORM や Python のコードにアク ... ... tructure is later changed with JavaScript. For instance, when binding a click handler, use $('body').on('click', selector, func) instead of $(selector).click(func) . This makes it easier for projects to extend Django's default behavior with JavaScrip ... 書く ¶ Django's JavaScript tests use QUnit . Here is an example test module: QUnit . module ( 'magicTricks' , { beforeEach : function () { const $ = django . jQuery ; $ ( '#qunit-fixture' ). append ( '<button class="button"></button>' ); } }); QUnit . ... test ( 'removeOnClick removes button on click' , function ( assert ) { const $ = django . jQuery ; removeOnClick ( '.button' ); assert . equal ( $ ( '.button' ). length , 1 ); ... 2026年10月08日