... ition header so that browsers # present the option to save the file. buffer . seek ( 0 ) return FileResponse ( buffer , as_attachment = True , filename = "hello.pdf" ) コードとコメントが自分自身の意味を説明しているはずですが、いくつかの点には言及しておくべ ... キュメントがHTMLファイルや一般的な application/octet-stream バイナリコンテンツではなく、PDFファイルであることを伝えます。 as_attachment=True が FileResponse に渡されると、適切な Content-Disposition ヘッダが設定され、ウェブブラウザはそのマシンでデフォルトが設 ... されていたとしても、そのドキュメントをどのように扱うかを確認するダイアログボックスをポップアップするようになります。もし as_attachment パラメータが省略された場合、ブラウザはPDFを扱うために設定されたプログラムやプラグインを使ってPDFを扱います。 任意の filena ... ... ith the appropriate CSV header. response = HttpResponse ( content_type = "text/csv" , headers = { "Content-Disposition" : 'attachment; filename="somefilename.csv"' }, ) writer = csv . writer ( response ) writer . writerow ([ "First row" , "Foo" , "Bar" , " ... ) return StreamingHttpResponse ( stream_batched_rows (), content_type = "text/csv" , headers = { "Content-Disposition" : 'attachment; filename="somefilename.csv"' }, ) テンプレートシステムを使う もしくは、 Django のテンプレートシステム を使って CSV を生成 ... ith the appropriate CSV header. response = HttpResponse ( content_type = "text/csv" , headers = { "Content-Disposition" : 'attachment; filename="somefilename.csv"' }, ) # The data is hardcoded here, but you could load it from a database or # some other sou ... ... des functions for conveniently sending email, as well as classes for building and sending more complex email messages with attachments and multiple content types. 注釈 django.core.mail で送信されるメールの文字セットは、 DEFAULT_CHARSET 設定の値にセットされ ... rough the send_mail() and related wrapper functions. If you wish to use advanced features, such as BCC'ed recipients, file attachments, or multi-part email, you'll need to create EmailMessage instances directly. 注釈 This is a design feature. send_mail() a ... sending the email. reply_to : メールを送信するときに "Reply-To" ヘッダ内で使われる、受信者のアドレスのリストまたはタプル。 attachments : A list of attachments to put on the message. Each can be an instance of MIMEPart or EmailAttachment , or a tuple with a ... ... ttpResponse ( ... my_data , ... headers = { ... "Content-Type" : "application/vnd.ms-excel" , ... "Content-Disposition" : 'attachment; filename="foo.xls"' , ... }, ... ) Content-Disposition ヘッダについては Django 固有のものはありませんが、その構文を忘れや ... 場合は、ビュー自体で 切断を処理する 必要があるかもしれません。 FileResponse オブジェクト class FileResponse ( open_file , as_attachment = False , filename = '' , ** kwargs ) [ソース] FileResponse はバイナリファイルに最適化された StreamingHttpResponse のサブク ... I サーバーが提供していれば wsgi.file_wrapper を使用し、そうでない場合はファイルを小さなチャンクでストリーミングします。 as_attachment=True だと、 Content-Disposition ヘッダーが attachment に設定され、ブラウザにファイルをダウンロードするように要求します。そ ... ... ルトでは現在時刻になります。 次の形式で文字列を出力します: Wdy, DD Mon YYYY HH:MM:SS GMT 。 content_disposition_header ( as_attachment , filename ) [ソース] RFC 6266 に指定された filename から Content-Disposition HTTPヘッダー値を構築します。 as_attachment が ... ... th_info() . Added the samesite argument to HttpResponse.set_cookie() to allow setting the SameSite cookie flag. The new as_attachment argument for FileResponse sets the Content-Disposition header to make the browser ask if the user wants to download the fi ... ... ad" commit where the test fails. Now, report your results on the Trac ticket, and please include the regression test as an attachment. When someone writes a fix for the bug, they'll already have your test as a starting point. Reviewing patches A great way ... ... ァイルフィールド名を、値としてアップロードしたいファイルへのファイルハンドルを渡すだけで十分です。例えば、フォームに name と attachment のフィールドがあり、後者が FileField の場合: >>> c = Client () >>> with open ( "wishlist.doc" , "rb" ) as fp : ... c . pos ... t ( "/customers/wishes/" , { "name" : "fred" , "attachment" : fp }) ... また、ファイルのようなオブジェクト (例えば StringIO や BytesIO ) をファイルハンドルとして指定することもできま ... ... ll back to MIME type application/octet-stream when binary content that can't be decoded as UTF-8 is specified for a text/* attachment. ファイルストレージ io.TextIOWrapper でラップできるように、 File に readable() 、 writable() 、 seekable() メソッドが追加さ ... 2026年10月08日