... にデータをバインドするには、辞書型のデータを Form クラスのコンストラクタの最初のパラメータとして渡します。 >>> data = { ... "subject" : "hello" , ... "message" : "Hi there" , ... "contact_email" : "foo@example.com" , ... "urgent" : True , ... } >>> f = Co ... きは、フォームの is_bound 属性の値を確認してください。 >>> f = ContactForm () >>> f . is_bound False >>> f = ContactForm ({ "subject" : "hello" }) >>> f . is_bound True 空の辞書を渡すと、データが空の バインドされた フォームが作成されることに注意してくださ ... スでは、 is_valid() メソッドを呼び出して検証を実行し、データが有効であるかどうかを示すブール値を返します。 >>> data = { ... "subject" : "hello" , ... "message" : "Hi there" , ... "contact_email" : "foo@example.com" , ... "urgent" : True , ... } >>> f = Co ... ... にデータをバインドするには、辞書型のデータを Form クラスのコンストラクタの最初のパラメータとして渡します。 >>> data = { ... "subject" : "hello" , ... "message" : "Hi there" , ... "contact_email" : "foo@example.com" , ... "urgent" : True , ... } >>> f = Co ... きは、フォームの is_bound 属性の値を確認してください。 >>> f = ContactForm () >>> f . is_bound False >>> f = ContactForm ({ "subject" : "hello" }) >>> f . is_bound True 空の辞書を渡すと、データが空の バインドされた フォームが作成されることに注意してくださ ... スでは、 is_valid() メソッドを呼び出して検証を実行し、データが有効であるかどうかを示すブール値を返します。 >>> data = { ... "subject" : "hello" , ... "message" : "Hi there" , ... "contact_email" : "foo@example.com" , ... "urgent" : True , ... } >>> f = Co ... ... たとえば、プレーンテキストのメッセージを送信するには、次のようにします。 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 ... mail.html" , context = { "my_variable" : 42 }, ) # Then, create a multipart email instance. msg = EmailMultiAlternatives ( subject = "Subject here" , body = text_content , from_email = "from@example.com" , to = [ "to@example.com" ], headers = { "List-Un ... 釈 django.core.mail で送信されるメールの文字セットは、 DEFAULT_CHARSET 設定の値にセットされます。 send_mail() ¶ send_mail ( subject , message , from_email , recipient_list , * , fail_silently = False , auth_user = None , auth_password = None , connection ... ... たとえば、プレーンテキストのメッセージを送信するには、次のようにします。 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 ... mail.html" , context = { "my_variable" : 42 }, ) # Then, create a multipart email instance. msg = EmailMultiAlternatives ( subject = "Subject here" , body = text_content , from_email = "from@example.com" , to = [ "to@example.com" ], headers = { "List-Un ... 釈 django.core.mail で送信されるメールの文字セットは、 DEFAULT_CHARSET 設定の値にセットされます。 send_mail() ¶ send_mail ( subject , message , from_email , recipient_list , * , fail_silently = False , auth_user = None , auth_password = None , connection ... ... dule-level function: from django.core.mail import send_mail from django.tasks import task @task def email_users ( emails , subject , message ): return send_mail ( subject = subject , message = message , from_email = None , recipient_list = emails ) The ... l import send_mail from django.tasks import task @task ( priority = 2 , queue_name = "emails" ) def email_users ( emails , subject , message ): return send_mail ( subject = subject , message = message , from_email = None , recipient_list = emails ) By c ... import task logger = logging . getLogger ( __name__ ) @task ( takes_context = True ) def email_users ( context , emails , subject , message ): logger . debug ( f "Attempt { context . attempt } to send user email. Task result id: { context . task_result ... ... dule-level function: from django.core.mail import send_mail from django.tasks import task @task def email_users ( emails , subject , message ): return send_mail ( subject = subject , message = message , from_email = None , recipient_list = emails ) The ... l import send_mail from django.tasks import task @task ( priority = 2 , queue_name = "emails" ) def email_users ( emails , subject , message ): return send_mail ( subject = subject , message = message , from_email = None , recipient_list = emails ) By c ... import task logger = logging . getLogger ( __name__ ) @task ( takes_context = True ) def email_users ( context , emails , subject , message ): logger . debug ( f "Attempt { context . attempt } to send user email. Task result id: { context . task_result ... ... 関係ありません。 このフィールドの使い方を示すために、 ContactForm を作成してみましょう: class ContactForm ( forms . Form ): subject = forms . CharField ( max_length = 100 ) message = forms . CharField () contact_email = forms . EmailField () recipients = ... ールドをクリーニングして検証する ¶ Suppose we add another requirement to our contact form: if the urgent field is True , the subject must contain "help" . We are performing validation on more than one field at a time, so the form's clean() method is a goo ... Everything as before. ... def clean ( self ): cleaned_data = super () . clean () urgent = cleaned_data . get ( "urgent" ) subject = cleaned_data . get ( "subject" ) if urgent and subject : # Only do something if both fields are valid so far. if "help" ... ... 関係ありません。 このフィールドの使い方を示すために、 ContactForm を作成してみましょう: class ContactForm ( forms . Form ): subject = forms . CharField ( max_length = 100 ) message = forms . CharField () contact_email = forms . EmailField () recipients = ... ールドをクリーニングして検証する ¶ Suppose we add another requirement to our contact form: if the urgent field is True , the subject must contain "help" . We are performing validation on more than one field at a time, so the form's clean() method is a goo ... Everything as before. ... def clean ( self ): cleaned_data = super () . clean () urgent = cleaned_data . get ( "urgent" ) subject = cleaned_data . get ( "subject" ) if urgent and subject : # Only do something if both fields are valid so far. if "help" ... ... 人のウェブサイトで "お問い合わせ" 機能を実装します: forms.py ¶ from django import forms class ContactForm ( forms . Form ): subject = forms . CharField ( max_length = 100 ) message = forms . CharField ( widget = forms . Textarea ) contact_email = forms . ... required = False ) Our earlier form used a single field, your_name , a CharField . In this case, our form has four fields: subject , message , contact_email and urgent . CharField , EmailField and BooleanField are just three of the available field types ... 、フォームデータを処理する方法は次のとおりです。 views.py ¶ from django.core.mail import EmailMessage if form . is_valid (): subject = form . cleaned_data [ "subject" ] message = form . cleaned_data [ "message" ] contact_email = form . cleaned_data [ "con ... ... 人のウェブサイトで "お問い合わせ" 機能を実装します: forms.py ¶ from django import forms class ContactForm ( forms . Form ): subject = forms . CharField ( max_length = 100 ) message = forms . CharField ( widget = forms . Textarea ) contact_email = forms . ... required = False ) Our earlier form used a single field, your_name , a CharField . In this case, our form has four fields: subject , message , contact_email and urgent . CharField , EmailField and BooleanField are just three of the available field types ... 、フォームデータを処理する方法は次のとおりです。 views.py ¶ from django.core.mail import EmailMessage if form . is_valid (): subject = form . cleaned_data [ "subject" ] message = form . cleaned_data [ "message" ] contact_email = form . cleaned_data [ "con ... 2026年10月08日