... django.views.decorators.http にある以下のデコレータを使って、特定のビューのキャッシュ動作を制御できます。 condition ( etag_func = None , last_modified_func = None ) [ソース] conditional_page () このデコレータを使用すると、ビューに ConditionalGetMiddl ... eware と同等の条件付き 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() によって ... ... ルフィールドを作成する を参照してください。 例 >>> 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 のような集計を含むすべての式の基本型です。これらは直接 ... ... 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 のコードにアク ... ... mail . endswith ( "@example.com" ): return redirect ( "/login/?next= %s " % request . path ) # ... user_passes_test ( test_func , login_url = None , redirect_field_name = 'next' ) [ソース] 便利なショートカットとして、 user_passes_test デコレータを使え ... uest ): ... class UserPassesTestMixin [ソース] クラスベースのビュー を使用する場合、 UserPassesTestMixin が使えます。 test_func () [ソース] 実行されるテストを提供するには、クラスの test_func() メソッドをオーバーライドする必要があります。さらに、 Acce ... できます。 from django.contrib.auth.mixins import UserPassesTestMixin class MyView ( UserPassesTestMixin , View ): def test_func ( self ): return self . request . user . email . endswith ( "@example.com" ) get_test_func () [ソース] また、 get_test_fun ... ... import ( DateTimeRangeField , RangeBoundary , RangeOperators , ) from django.db import models from django.db.models import Func , Q class TsTzRange ( Func ): function = "TSTZRANGE" output_field = DateTimeRangeField () class Reservation ( models . Mod ... ... enticate() (django.contrib.auth モジュール) (ModelBackend のメソッド) (RemoteUserBackend のメソッド) Abs (django.db.models.functions のクラス) ABSOLUTE_URL_OVERRIDES setting abstract (Options の属性) abulk_create() (django.db.models.query.QuerySet モ ... gure_user() (RemoteUserBackend のメソッド) acontains() (django.db.models.query.QuerySet モジュール) ACos (django.db.models.functions のクラス) acount() (django.db.models.query.QuerySet モジュール) acreate() (django.db.models.query.QuerySet モジュール ... els モジュール) ArchiveIndexView (django.views.generic.dates のクラス) (組み込みクラス) Area (django.contrib.gis.db.models.functions のクラス) (django.contrib.gis.measure のクラス) area (GEOSGeometry の属性) (OGRGeometry の属性) arefresh() (TaskResul ... ... RL が解決しない場合、その関数は Resolver404 例外を発生させます( Http404 のサブクラスです)。 class ResolverMatch [ソース] func URL を提供するために使用されるビュー関数 args URL からパースされた、ビュー関数に渡される引数。 kwargs ビュー関数に渡される ... L pattern that matches the URL print ( match . url_name ) ResolverMatch オブジェクトは、3値タプルに代入することもできます: func , args , kwargs = resolve ( "/some/path/" ) resolve() の可能な使用例の一つは、リダイレクトする前にビューが Http404 エラーを ... ... 生成を上書きするためにデータを提供する必要がありそうな場合は、このメソッドにカスタムキーワード引数を定義できます。たとえば、 Func.as_sql() を参照してください。 as_vendorname ( compiler , connection ) as_sql() メソッドと同じように動作します。式が compil ... ws the Query Expression API , which implies that you can use <expression>__<transform1>__<transform2> . It's a specialized Func() expression that only accepts one argument. It can also be used on the right hand side of a filter or directly as an anno ... 2026年10月08日