... = forms . Textarea ) def send_email ( self ): # send email using the self.cleaned_data dictionary pass このとき、ビューは FormView を使うことで構築できます。 views.py from myapp.forms import ContactForm from django.views.generic.edit import FormView cla ... ss ContactFormView ( FormView ): template_name = "contact.html" form_class = ContactForm success_url = "/thanks/" def form_valid ( self , for ... data has been POSTed. # It should return an HttpResponse. form . send_email () return super () . form_valid ( form ) メモ: FormView は TemplateResponseMixin を継承するため、ここでは template_name を使うことができます。 form_valid() デフォルトの実装は、た ... ... ield ( max_length = 200 ) def get_absolute_url ( self ): return reverse ( "author-detail" , kwargs = { "pk" : self . pk }) FormView class django.views.generic.edit. FormView フォームを描画するビューです。エラー時には、バリデーションエラーとともにフォーム ... 下のビューからメソッドと属性を継承しています: django.views.generic.base.TemplateResponseMixin django.views.generic.edit.BaseFormView django.views.generic.edit.FormMixin django.views.generic.edit.ProcessFormView django.views.generic.base.View 例 myapp/form ... cleaned_data dictionary pass 例 myapp/views.py : from myapp.forms import ContactForm from django.views.generic.edit import FormView class ContactFormView ( FormView ): template_name = "contact.html" form_class = ContactForm success_url = "/thanks/" def f ... ... オブジェクトや複数のオブジェクトを扱う際に便利な機能を提供する4つのミックスインについて紹介します。 ジェネリック編集ビュー ( FormView と、モデル固有のビュー CreateView , UpdateView , DeleteView ) と日付ベースのジェネリックビューにもミックスインがあります。 ... OST 時にフォームが適切に呼び出されるようにコードを少し書きましょう。 注釈 FormMixin を使用し、自分で post() を実装します。 FormView (すでに適切な post() を提供している)と DetailView は、両方のビューが get() を実装しているため、混在させるとより混乱する可 ... フォームを処理するための別々のビューを持つ方が、上記のアプローチよりも作業量が少ないでしょう。その場合、 DetailView とは別の FormView を使うことになるでしょう。 もう一つのより良い解決策 ここで本当にやろうとしていることは、同じURLから2つの異なるクラスベース ... ... y view) DetailView ListView ジェネリック編集ビュー (Generic editing view) FormView CreateView UpdateView DeleteView ジェネリック日付ビュー ArchiveIndexView YearArchiveView MonthArchiveView WeekArchiveView ... n) MultipleObjectMixin MultipleObjectTemplateResponseMixin ミックスイン (mixin) を編集する FormMixin ModelFormMixin ProcessFormView DeletionMixin 日付ベースのミックスイン (mixin) YearMixin MonthMixin DayMixin WeekMixin DateMixin BaseDateListView クラスベ ... デックス シンプルなジェネリックビュー View TemplateView RedirectView 詳細ビュー DetailView リストビュー ListView 編集ビュー FormView CreateView UpdateView DeleteView 日付ベースのビュー ArchiveIndexView YearArchiveView MonthArchiveView WeekArchiveView DayA ... ... t class FileFieldForm ( forms . Form ): file_field = MultipleFileField () そして、複数のアップロードファイルを扱うために、 FormView サブクラスの form_valid() メソッドをオーバーライドします。 views.py from django.views.generic.edit import FormView from .f ... orms import FileFieldForm class FileFieldFormView ( FormView ): form_class = FileFieldForm template_name = "upload.html" # Replace with your template. success_url = "..." # ... ... ontext_data() get_paginator() head() http_method_not_allowed() paginate_queryset() render_to_response() setup() 編集ビュー FormView class FormView 属性 (とオプションのアクセサ): content_type extra_context form_class [ get_form_class() ] http_method_names ... ... す。それ以外の理由で発生する失敗は隠されません。 クラスベースのビューにメッセージを追加する class views. SuccessMessageMixin FormView をベースにしたクラスに、成功メッセージ属性を追加します。 get_success_message ( cleaned_data ) cleaned_data はフォームからの ... ... it.BaseCreateView (組み込みクラス) django.views.generic.edit.BaseDeleteView (組み込みクラス) django.views.generic.edit.BaseFormView (組み込みクラス) django.views.generic.edit.BaseUpdateView (組み込みクラス) django.views.generic.edit.CreateView (組み込みク ... generic.edit.DeletionMixin (組み込みクラス) django.views.generic.edit.FormMixin (組み込みクラス) django.views.generic.edit.FormView (組み込みクラス) django.views.generic.edit.ModelFormMixin (組み込みクラス) django.views.generic.edit.ProcessFormView (組み ... (InlineModelAdmin の属性) formset_factory() (django.forms.formsets モジュール) formset_template_name (BaseRenderer の属性) FormView (組み込みクラス) frame_type (RowRange の属性) (ValueRange の属性) from_bbox() (OGRGeometry のクラスメソッド) (Polygon のク ... ... nd now uses the latest pickle protocol available. Added SuccessMessageMixin which provides a success_message attribute for FormView based classes. Added the django.db.models.ForeignKey.db_constraint and django.db.models.ManyToManyField.db_constraint opti ... 2026年10月08日