... ContextMixin メソッドと属性 initial フォームの初期化データのディクショナリ。 form_class インスタンス化するフォームクラス。 success_url フォームが正常に処理されたときにリダイレクトするURL。 prefix 生成されるフォームの prefix 。 get_initial () フォームの初 ... t.FILES ) も提供されます。 get_prefix () 生成されるフォームの prefix を特定します。 デフォルトでは prefix を返します。 get_success_url () フォームのバリデーションに成功したときにリダイレクトする URL を特定します。 デフォルトでは success_url を返します。 ... form_valid ( form ) get_success_url() にリダイレクトします。 form_invalid ( form ) 無効なフォームをコンテキストとして提供し、レスポンスをレンダリングします ... ... 的 DEBUG プロダクション環境では無視 (ないし削除) される、開発に関連したメッセージ INFO ユーザーに何か情報を伝えるメッセージ SUCCESS あるアクションが成功した、例えば "あなたのプロフィールは無事に更新されました" WARNING 問題は起きなかったが、問題になり得る ... フォルトでは、それぞれのレベルは、レベル定数を小文字にした、単一のタグを持っています。 レベル定数 タグ DEBUG debug INFO info SUCCESS success WARNING warning ERROR error メッセージレベル (ビルトインないしカスタムのいずれか) のデフォルトのタグを変更するため ... SQL statements were executed." % count ) messages . info ( request , "Three credits remain in your account." ) messages . success ( request , "Profile details updated." ) messages . warning ( request , "Your account expires in three days." ) messages . ... ... form_class() ] http_method_names initial [ get_initial() ] prefix [ get_prefix() ] response_class [ render_to_response() ] success_url [ get_success_url() ] template_engine template_name [ get_template_names() ] メソッド as_view() dispatch() form_invali ... nd_slug queryset [ get_queryset() ] response_class [ render_to_response() ] slug_field [ get_slug_field() ] slug_url_kwarg success_url [ get_success_url() ] template_engine template_name [ get_template_names() ] template_name_field template_name_suffix ... nd_slug queryset [ get_queryset() ] response_class [ render_to_response() ] slug_field [ get_slug_field() ] slug_url_kwarg success_url [ get_success_url() ] template_engine template_name [ get_template_names() ] template_name_field template_name_suffix ... ... s.generic.edit import FormView class ContactFormView ( FormView ): template_name = "contact.html" form_class = ContactForm success_url = "/thanks/" def form_valid ( self , form ): # This method is called when valid form data has been POSTed. # It should ... plateResponseMixin を継承するため、ここでは template_name を使うことができます。 form_valid() デフォルトの実装は、ただ単に success_url にリダイレクトするというものです。 モデルフォーム Generic views really shine when working with models. These generic v ... ally. You can override this if you have any special requirements; see below for examples. You don't even need to provide a success_url for CreateView or UpdateView - they will use get_absolute_url() on the model object if available. カスタムの ModelForm ... ... equest . FILES ) if form . is_valid (): handle_uploaded_file ( request . FILES [ "file" ]) return HttpResponseRedirect ( "/success/url/" ) else : form = UploadFileForm () return render ( request , "upload.html" , { "form" : form }) ここで、 request.FILE ... ( request . POST , request . FILES ) if form . is_valid (): # file is saved form . save () return HttpResponseRedirect ( "/success/url/" ) else : form = ModelFormWithFileField () return render ( request , "upload.html" , { "form" : form }) 手動でオブジェ ... nstance = ModelWithFileField ( file_field = request . FILES [ "file" ]) instance . save () return HttpResponseRedirect ( "/success/url/" ) else : form = UploadFileForm () return render ( request , "upload.html" , { "form" : form }) リクエストの外で手動で ... ... ate ( request , username = username , password = password ) if user is not None : login ( request , user ) # Redirect to a success page. ... else : # Return an 'invalid login' error message. ... 認証バックエンドの選択 ユーザーがログインするとき、そのユー ... urn value. Example: from django.contrib.auth import logout def logout_view ( request ): logout ( request ) # Redirect to a success page. Note that logout() doesn't throw any errors if the user wasn't logged in. When you call logout() , the session data ... ed() デコレータを使用したときに raise_exception パラメータを使用しない限り、リダイレクトループが発生する可能性があります。 success_url_allowed_hosts ログイン後にリダイレクトしても安全なホストの set を、 request.get_host() に加えて指定します。デフォルトは ... ... d i18n ) to redirect the user to an "on success" URL. The security checks for these redirects (namely django.utils.http.is_safe_url() ) accepted URLs with leading control ... ... o.contrib.auth.views.login() and i18n ) to redirect the user to an "on success" URL. The security check for these redirects (namely django.utils.http.is_safe_url() ) considered some numeric URLs (e.g. ... ... e.g. django.contrib.auth.views.login() and i18n ) to redirect the user to an "on success" URL. The security check for these redirects (namely django.utils.http.is_safe_url() ) considered some numeric URLs (e.g. ... ... n some cases (e.g. django.contrib.auth.views.login() , django.contrib.comments , and i18n ) to redirect the user to an "on success" URL. The security checks for these redirects (namely django.utils.http.is_safe_url() ) didn't check if the scheme is http ... 2026年10月08日