... >> class ArticleForm ( forms . Form ): ... title = forms . CharField () ... pub_date = forms . DateField () ... ユーザーが一度に複数の記事を作成 ... できるようにしたいと思うかもしれません。 ArticleForm からフォームセットを作るには、次のようにします: >>> from django.forms import formset_factory >>> ArticleFormSet = formset_ ... factory ( ArticleForm ) これで ArticleFormSet という名前のフォームセットクラスが作成されました。フォームセットをインスタンス化することで、フォー ... ... (unbound) フォーム Form のインスタンスには、データセットに バインドされている (bound な) ものと バインドされていない (unbound な) ものがあります。 ... データセットに バインドされた Form インスタンスであれば、そのデータをバリデーションしたり、HTMLとしてフォームをレンダリングし、HTMLにデータを表示したりするこ ... とができます。 データセットに バインドされていない Form インスタンスでは、(検証するデータがないので)データをバリデーションすることはできませんが、空のフォームをHTMLとしてレンダ ... ... 入れ、そのデータを処理したあと、入力に応じたレスポンスを返すことができるようになります。 HTML フォーム HTMLでは、フォームは <form>...</form> 内の要素の集まりで、訪問者によるテキスト入力、オプション選択、オブジェクトやコントロールの操作などを可能にし、こ ... jango が次の行動を決めるために使われる、ユーザーからは見えない隠しテキストフィールドもあります。 また、フォームのデータが <form> の action 属性によって指定された URL - /admin/ - に送信されるべきこと、そして method 属性によって指定されたHTTP メカニズム ... と値を含みます。実際に、Django ドキュメンテーションで何かを検索してみると、フォーム https://docs.djangoproject.com/search/?q=forms&release=1 といった URL が生成されるのが分かるでしょう。 GET と POST は、一般的には異なる目的に使われます。 システムの状態 ... ... が定義されているので、フォーム内にフィールドタイプを改めて定義するのは冗長でしょう。 このためDjango には、Django モデルから Form クラスを生成できるようなヘルパークラスを用意してあります。 例えば次のようにします: >>> from django.forms import ModelForm ... >>> from myapp.models import Article # Create the form class. >>> class ArticleForm ( ModelForm ): ... class Meta : ... model = Article ... fields = [ "pub_date" , "headline" , ... "content" , "reporter" ] ... # Creating a form to add an article. >>> form = ArticleForm () # Creating a form to change an existing article. >>> article = Article . obje ... ... ームを処理するための一般的なクラスビューを用意しています。 基本的なフォーム 以下のようなコンタクトフォームがあったとします。 forms.py from django import forms class ContactForm ( forms . Form ): name = forms . CharField () message = forms . CharField ( ... widget = forms . Textarea ) def send_email ( self ): # send email using the self.cleaned_data dictionary pass このとき、ビューは FormVie ... w を使うことで構築できます。 views.py from myapp.forms import ContactForm from django.views.generic.edit import FormView class ContactFormView ( FormView ): template_name = "co ... ... 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/ ... forms.py : from django import forms class ContactForm ( forms . Form ): name = forms . CharField () message = forms . CharField ( widget = forms . Textarea ) ... ... tionMixin 注釈 これらの編集ビューへの結合され方の例は、 ジェネリック編集ビュー (Generic editing view) を参照してください。 FormMixin class django.views.generic.edit. FormMixin フォームを作成したり表示したりする機能を提供するmixinクラス。 ミックスイン ... django.views.generic.base.ContextMixin メソッドと属性 initial フォームの初期化データのディクショナリ。 form_class インスタンス化するフォームクラス。 success_url フォームが正常に処理されたときにリダイレクトするURL。 prefix 生成され ... るフォームの prefix 。 get_initial () フォームの初期データを取得します。デフォルトでは、 initial のコピーを返します。 get_form_class () インスタンス化するフォームクラスを取得します。デフォルトでは form_class です。 get_form ( form_class = None ) get ... ... sponse from django.views import View class AsyncView ( View ): async def get ( self , request , * args , ** kwargs ): # Perform view logic using await. await asyncio . sleep ( 1 ) return HttpResponse ( "Hello async world!" ) 詳細は 非同期のクラスベー ... heck , unique , and exclusion constraints defined in the Meta.constraints option are now checked during model validation . Form rendering accessibility In order to aid users with screen readers, and other assistive technology, new <div> based form te ... roup related controls, such as radio-lists, into fieldsets. The new templates are recommended, and will become the default form rendering style when outputting a form, like {{ form }} in a template, from Django 5.0. In order to ease adopting the new ... ... したコンテンツ のセキュリティガイドをご覧ください。 ファイルのアップロードの基本 FileField を持つフォームを考えてみましょう: forms.py from django import forms class UploadFileForm ( forms . Form ): title = forms . CharField ( max_length = 50 ) file = f ... 格納されるのは、リクエストメソッドが POST で、少なくとも1つのファイルフィールドが実際に投稿され、かつリクエストをポストした <form> の属性に enctype="multipart/form-data" が設定されていた場合に限られることに注意してください。そうでない場合には、 request ... 場合、下記のようになります: views.py from django.http import HttpResponseRedirect from django.shortcuts import render from .forms import UploadFileForm # Imaginary function to handle an uploaded file. from somewhere import handle_uploaded_file def upl ... ... ip enriched us. His consideration, patience, and dedication will always be an inspiration to us. This release of Django is for Malcolm. -- The Django Developers November 6, 2013 Django 1.6 へようこそ! These release notes cover the new features , as w ... Database-level autocommit is now turned on by default. This makes transaction handling more explicit and should improve performance. The existing APIs were deprecated, and new APIs were introduced, as described in the transaction management docs . Pe ... ethod_name pseudo-paths. This allows running tests located anywhere in your codebase, rather than only in INSTALLED_APPS . For more details, see Django におけるテスト . This change is backwards-incompatible; see the backwards-incompatibility notes . ... 2026年10月08日