... jango.http import HttpResponse from django.views import View class MyView ( View ): def get ( self , request , * args , ** kwargs ): return HttpResponse ( "Hello, World!" ) Example urls.py : from django.urls import path from myapp.views import MyView u ... ルト値: [ "get" , "post" , "put" , "patch" , "delete" , "head" , "options" , "trace" ] メソッド classmethod as_view ( ** initkwargs ) リクエストを受け取ってレスポンスを返す、呼び出し可能なビューを返します: response = MyView . as_view ()( request ) 返され ... たビューは、 view_class と view_initkwargs 属性を持っています。 リクエスト/レスポンスサイクル中にビューが呼び出されると、 setup() メソッドは HttpRequest をビューの r ... ... も指定します(これがどういう意味かについては required セクションを参照してください)。 BooleanField class BooleanField ( ** kwargs ) [ソース] デフォルトのウィジェット: CheckboxInput 空の値: False 正規化後の値: Pythonの True または False になります。 フィ ... 含めたい場合は、 BooleanField を作成する際に required=False を渡すことを忘れないでください。 CharField class CharField ( ** kwargs ) [ソース] デフォルトのウィジェット: TextInput 空の値: empty_value として与えたもの 正規化後の値: 文字列になります。 max_l ... が削除されます。 empty_value 「空」を表すのに使用する値です。デフォルトは空の文字列です。 ChoiceField class ChoiceField ( ** kwargs ) [ソース] デフォルトのウィジェット: Select 空の値: '' (空の文字列) 正規化後の値: 文字列になります。 指定された値が選択肢の ... ... n , View ): """Records the current user's interest in an author.""" model = Author def post ( self , request , * args , ** kwargs ): if not request . user . is_authenticated : return HttpResponseForbidden () # Look up the author we're interested in. se ... = self . get_object () # Actually record interest somehow here! return HttpResponseRedirect ( reverse ( "author-detail" , kwargs = { "pk" : self . object . pk }) ) 実際には、リレーショナルデータベースではなく、キーバリューストアに関心事を記録したいと思 ... ctMixin , ListView ): paginate_by = 2 template_name = "books/publisher_detail.html" def get ( self , request , * args , ** kwargs ): self . object = self . get_object ( queryset = Publisher . objects . all ()) return super () . get ( request , * args , ... ... ngo.urls import reverse def myview ( request ): return HttpResponseRedirect ( reverse ( "arch-summary" , args = [ 1945 ])) kwargs を args の代わりに渡すこともできます。例えば: >>> reverse ( "admin:app_list" , kwargs = { "app_label" : "auth" }) '/admin/ ... auth/' args と kwargs を同時に reverse() に渡すことはできません。 一致するものが見つからない場合、 reverse() は NoReverseMatch 例外を発生させます ... してください。 reverse_lazy() reverse() の遅延評価バージョンです。 reverse_lazy ( viewname , urlconf = None , args = None , kwargs = None , current_app = None , * , query = None , fragment = None ) プロジェクトの URLConf がロードされる前に、URL 反転を使 ... ... のスタブチェック関数です。 from django.core.checks import Error , register @register () def example_check ( app_configs , ** kwargs ): errors = [] # ... your check logic here if check_failed : errors . append ( Error ( "an error" , hint = "A hint." , obj ... あるデータベースエイリアスのリストです。 databases が None の場合、チェックはどのデータベース接続も使用してはいけません。 **kwargs 引数は将来の拡張のために必要です。 メッセージ 関数は、メッセージのリストを返さなければなりません。チェックの結果、問題が見 ... 出します: from django.core.checks import register , Tags @register ( Tags . compatibility ) def my_check ( app_configs , ** kwargs ): # ... perform compatibility checks and collect errors return errors 以下のように、本番用の設定ファイルにのみ関係する「デ ... ... odels class HandField ( models . Field ): description = "A hand of cards (bridge style)" def __init__ ( self , * args , ** kwargs ): kwargs [ "max_length" ] = 104 super () . __init__ ( * args , ** kwargs ) 私たちの HandField は、ほとんどの標準フィールド ... ード引数から削除できます: from django.db import models class HandField ( models . Field ): def __init__ ( self , * args , ** kwargs ): kwargs [ "max_length" ] = 104 super () . __init__ ( * args , ** kwargs ) def deconstruct ( self ): name , path , args , ... kwargs = super () . deconstruct () del kwargs [ "max_length" ] return name , path , args , kwargs 新しいキーワード引数を追加する場 ... ... ができます: from django.apps import AppConfig from django.core.signals import setting_changed def my_receiver ( sender , ** kwargs ): print ( "Setting changed!" ) class MyAppConfig ( AppConfig ): ... def ready ( self ): setting_changed . connect ( my_re ... ーバ関数を定義する必要があります。レシーバはPythonの関数やメソッドであれば何でもかまいません: def my_receiver ( sender , ** kwargs ): print ( "Request finished!" ) Notice that the function takes a sender argument, along with wildcard keyword arguments ( ... **kwargs ); all signal receivers must take these arguments. We'll look at senders a bit later , but right now look at the **kwargs ... ... () インスタンス化するフォームクラスを取得します。デフォルトでは form_class です。 get_form ( form_class = None ) get_form_kwargs() を使用して form_class のインスタンスを生成します。 form_class が指定されていない場合は get_form_class() が使用されます。 ... get_form_kwargs () フォームのインスタンス化に必要なキーワード引数を構築します。 引数 initial には get_initial() を指定します。 リクエストが ... す。 form_invalid ( form ) 無効なフォームをコンテキストとして提供し、レスポンスをレンダリングします。 get_context_data ( ** kwargs ) get_form() を呼び出して、その結果を "form" という名前でコンテキストデータに追加します。 ModelFormMixin class django.view ... ... タは、model admin クラスをその __init__() メソッド内で参照する必要がある場合(例: super(PersonAdmin, self).__init__(*args, **kwargs) )には使用できません。代わりに super().__init__(*args, **kwargs) のようにします。 admin ファイルを見つける INSTALLED_APPS ... mport reverse class PersonAdmin ( admin . ModelAdmin ): def view_on_site ( self , obj ): url = reverse ( "person-detail" , kwargs = { "slug" : obj . slug }) return "https://example.com" + url カスタムテンプレートのオプション admin テンプレートをオーバー ... n 属性を持ちます。その他の AdminSite ビューは admin_site 属性を持ちます。 ModelAdmin. get_form ( request , obj = None , ** kwargs ) [ソース] admin の追加と変更のビューで使うための ModelForm クラスを返します。 add_view() と change_view() を参照してくださ ... ... ion The task decorator task ( * , priority = 0 , queue_name = 'default' , backend = 'default' , takes_context = False , ** kwargs ) [ソース] The @task decorator defines a Task instance. All keyword arguments are passed directly to the backend's task_cl ... @task decorator: @task ( foo = 5 , bar = 600 ) def my_task (): pass Changed in Django 6.1: Support for passing arbitrary **kwargs to the @task decorator is added. If the defined Task is not valid according to the backend, InvalidTask is raised. See def ... following attributes: priority backend queue_name run_after See modifying Tasks for usage examples. enqueue ( * args , ** kwargs ) [ソース] Enqueues the Task to the Task backend for later execution. Arguments are passed to the Task 's function after a ... 2026年10月08日