... 、辞書型のデータを Form クラスのコンストラクタの最初のパラメータとして渡します。 >>> data = { ... "subject" : "hello" , ... "message" : "Hi there" , ... "contact_email" : "foo@example.com" , ... "urgent" : True , ... } >>> f = ContactForm ( data ) この辞書 ... ドを呼び出して検証を実行し、データが有効であるかどうかを示すブール値を返します。 >>> data = { ... "subject" : "hello" , ... "message" : "Hi there" , ... "contact_email" : "foo@example.com" , ... "urgent" : True , ... } >>> f = ContactForm ( data ) >>> f . ... is_valid () True Let's try with some invalid data. In this case, subject is blank (an error, because all fields are required by default) and contact_email is not a valid email address: >>> data = { ... "subject" : ... ... クエスト) 内で表示するために、これらを検索することを可能にします。全てのメッセージは、優先順位 (たとえば info 、 warning 、 error ) を決定づける特定の level でタグづけされます。 メッセージを有効にする メッセージは、 ミドルウェア クラスと、それに対応する ... によって生成されたデフォルトの settings.py は、メッセージ機能を有効にするために必要な設定を全て含んでいます: 'django.contrib.messages' は、 INSTALLED_APPS の中にあります。 MIDDLEWARE は 'django.contrib.sessions.middleware.SessionMiddleware' と 'django.con ... trib.messages.middleware.MessageMiddleware' を含みます。 デフォルトの ストレージバックエンド は sessions に依存します。そのため Session ... ... ッセージを送信するには、次のようにします。 from django.core.mail import send_mail send_mail ( "Subject here" , "Here is the message." , "from@example.com" , [ "to@example.com" ], ) When additional email sending functionality is needed, use the EmailMessa ... s printed to the console as a development aid (for projects created with startproject ) or results in a MailerDoesNotExist error (when the MAILERS setting isn't defined). Use the MAILERS setting to tell Django how to send email. For example, to send t ... o substitute Django's memory email backend . This prevents test cases from sending real email and gives them access to the messages that would have been sent. 開発用にメールを設定する discusses some other approaches. Changed in Django 6.1: In earlier re ... ... ving the wrong value when it didn't match the current time zone on the server. In addition, the widgets now display a help message when the browser and server time zone are different, to clarify how the value inserted in the field will be interpreted. U ... more information about both custom lookups and transforms refer to the custom lookups documentation. Improvements to Form error handling Form.add_error() Previously there were two main patterns for handling errors in forms: Raising a ValidationError ... from within certain functions (e.g. Field.clean() , Form.clean_<fieldname>() , or Form.clean() for non-field errors.) Fiddling with Form._errors when targeting a specific field in Form.clean() or adding errors from outside of a "clean" m ... ... リデーション 制約は モデルのバリデーション の間にチェックされます。 BaseConstraint class BaseConstraint ( * name , violation_error_code = None , violation_error_message = None ) [ソース] すべての制約の基底クラスです。サブクラスは constraint_sql() , crea ... パラメータは以下の通りです: name BaseConstraint. name 制約の名前。制約には常に一意な名前を指定する必要があります。 violation_error_code BaseConstraint. violation_error_code モデルのバリデーション 中に ValidationError が発生した場合に使用されるエラーコー ... ドです。デフォルトは None です。 violation_error_message BaseConstraint. violation_error_message モデルのバリデーション の実行中に ValidationError が発生した場合に表示されるエラー ... ... ジをコンソールに送信します。 DEBUG が False のとき: django ロガーは、 django ヒエラルキー ( django.server を除く) において、 ERROR ないし CRITICAL レベルを AdminEmailHandler に送信します。 DEBUG の値にかかわらず: django.server ロガーは INFO レベル以上の ... e" , }, }, "formatters" : { "django.server" : { "()" : "django.utils.log.ServerFormatter" , "format" : "[ {server_time} ] {message} " , "style" : "{" , } }, "handlers" : { "console" : { "level" : "INFO" , "filters" : [ "require_debug_true" ], "class" : ... : { "level" : "INFO" , "class" : "logging.StreamHandler" , "formatter" : "django.server" , }, "mail_admins" : { "level" : "ERROR" , "filters" : [ "require_debug_false" ], "class" : "django.utils.log.AdminEmailHandler" , }, }, "loggers" : { "django" : ... ... SL_KEYFILE settings. The SMTP EmailBackend now supports setting the timeout parameter with the EMAIL_TIMEOUT setting. EmailMessage and EmailMultiAlternatives now support the reply_to parameter. ファイルストレージ Storage.get_available_name() and Storage ... -level maximum filename length constraints. Filenames exceeding this argument will get truncated. This prevents a database error when appending a unique suffix to a long filename that already exists on the storage. See the deprecation note about addin ... lasses. フォーム Form widgets now render attributes with a value of True or False as HTML5 boolean attributes. The new has_error() method allows checking if a specific error has happened. If required_css_class is defined on a form, then the <label> ta ... ... 種類のチェックを実行する関数を書くことができます。以下は、例としてのスタブチェック関数です。 from django.core.checks import Error , register @register () def example_check ( app_configs , ** kwargs ): errors = [] # ... your check logic here if check_fa ... iled : errors . append ( Error ( "an error" , hint = "A hint." , obj = checked_object , id = "myapp.E001" , ) ) return errors チェック関 ... が見つからない場合、チェック関数は空のリストを返さなければなりません。 チェックメソッドで発生させる警告やエラーは、必ず CheckMessage のインスタンスでなければなりません。 CheckMessage のインスタンスは、1つの報告可能なエラーや警告をカプセル化します。また、メ ... ... 上の is_valid() メソッドを呼び出したときに実行されます。このほかにも、クリーニングとバリデーションのトリガーとなる処理 (直接 errors 属性にアクセスしたり、 full_clean() を直接呼び出す) がありますが、通常必要とはなりません。 一般的に、あらゆるクリーニング ... 方法は ValidationError を投げる可能性があります。処理されるデータに問題がある場合、関連情報を ValidationError コンストラクタに渡します。 下記項目 ... に、 ContactForm を作成してみましょう: class ContactForm ( forms . Form ): subject = forms . CharField ( max_length = 100 ) message = forms . CharField () contact_email = forms . EmailField () recipients = MultiEmailField () urgent = forms . BooleanField ... ... onstraint ( * , name , expressions , index_type = None , condition = None , deferrable = None , include = None , violation_error_code = None , violation_error_message = None ) [ソース] データベースに排他制約を作成します。内部的には、PostgreSQLはインデ ... ion マイグレーションオペレーションを使ってインストールできます。 既存の行と競合する新しい行を挿入しようとすると、 IntegrityError が発生します。更新が既存の行と競合する場合も同様です。 排他制約は モデル バリデーション の間にチェックされます。 name Excl ... ルのバリデーション 中に ValidationError が発生した場合に使用されるエラーコードです。デフォルトは None です。 violation_error_message モデルのバリデーション 中に ValidationError が発生した場合に使用されるエラーメッセージです。デフォルトは BaseConstraint.vi ... 2026年10月08日