... the documentation for your version of Django, as the exact code necessary is different for some older versions of Django. FileField no longer deletes files ¶ In earlier Django versions, when a model instance containing a FileField was deleted, FileField ... s scenarios, including rolled-back transactions and fields on different models referencing the same file. In Django 1.2.5, FileField will never delete files from the backend storage. If you need cleanup of orphaned files, you'll need to handle it yourself ... his function has changed. 目次 Django 1.2.5 リリースノート Backwards incompatible changes CSRF exception for AJAX requests FileField no longer deletes files Use of custom SQL to load initial data in tests ModelAdmin.lookup_allowed signature changed 前のト ... ... the documentation for your version of Django, as the exact code necessary is different for some older versions of Django. FileField no longer deletes files ¶ In earlier Django versions, when a model instance containing a FileField was deleted, FileField ... s scenarios, including rolled-back transactions and fields on different models referencing the same file. In Django 1.2.5, FileField will never delete files from the backend storage. If you need cleanup of orphaned files, you'll need to handle it yourself ... his function has changed. 目次 Django 1.2.5 リリースノート Backwards incompatible changes CSRF exception for AJAX requests FileField no longer deletes files Use of custom SQL to load initial data in tests ModelAdmin.lookup_allowed signature changed 前のト ... ... !緩和策の詳細は、 ユーザーがアップロードしたコンテンツ のセキュリティガイドをご覧ください。 ファイルのアップロードの基本 ¶ FileField を持つフォームを考えてみましょう: forms.py ¶ from django import forms class UploadFileForm ( forms . Form ): title = forms ... . CharField ( max_length = 50 ) file = forms . FileField () このフォームをハンドリングするビューは、ファイルのデータを request.FILES というディクショナリの中に受け取ります。このデ ... ィクショナリには、キーと、それぞれのキーに対応するフォームの FileField (または ImageField または他の FileField のサブクラス) が格納されています。そのため、上のフォームから送信されたデータには、 ... ... !緩和策の詳細は、 ユーザーがアップロードしたコンテンツ のセキュリティガイドをご覧ください。 ファイルのアップロードの基本 ¶ FileField を持つフォームを考えてみましょう: forms.py ¶ from django import forms class UploadFileForm ( forms . Form ): title = forms ... . CharField ( max_length = 50 ) file = forms . FileField () このフォームをハンドリングするビューは、ファイルのデータを request.FILES というディクショナリの中に受け取ります。このデ ... ィクショナリには、キーと、それぞれのキーに対応するフォームの FileField (または ImageField または他の FileField のサブクラス) が格納されています。そのため、上のフォームから送信されたデータには、 ... ... を提供しています。このドキュメントの後半では、それらのストレージシステムの働きについて説明します。 モデルでファイルを使う ¶ FileField や ImageField を使うと、 Django はそのファイルを扱うために使える API を提供します。 次のモデルを考えてみましょう。 ImageFi ... . DecimalField ( max_digits = 5 , decimal_places = 2 ) photo = models . ImageField ( upload_to = "cars" ) specs = models . FileField ( upload_to = "specs" ) どの Car インスタンスにも photo 属性があり、それを使って添付写真の詳細を見ることができます: >>> ca ... () >>> car . photo . path '/media/cars/chevy_ii.jpg' >>> car . photo . path == new_path True ディスク上の既存のファイルを FileField に保存します: >>> from pathlib import Path >>> from django.core.files import File >>> path = Path ( "/some/external/specs. ... ... を提供しています。このドキュメントの後半では、それらのストレージシステムの働きについて説明します。 モデルでファイルを使う ¶ FileField や ImageField を使うと、 Django はそのファイルを扱うために使える API を提供します。 次のモデルを考えてみましょう。 ImageFi ... . DecimalField ( max_digits = 5 , decimal_places = 2 ) photo = models . ImageField ( upload_to = "cars" ) specs = models . FileField ( upload_to = "specs" ) どの Car インスタンスにも photo 属性があり、それを使って添付写真の詳細を見ることができます: >>> ca ... () >>> car . photo . path '/media/cars/chevy_ii.jpg' >>> car . photo . path == new_path True ディスク上の既存のファイルを FileField に保存します: >>> from pathlib import Path >>> from django.core.files import File >>> path = Path ( "/some/external/specs. ... ... rarchy . Deleting a model doesn't delete associated files ¶ In earlier Django versions, when a model instance containing a FileField was deleted, FileField took it upon itself to also delete the file from the backend storage. This opened the door to sever ... led-back transactions and fields on different models referencing the same file. In Django 1.3, when a model is deleted the FileField 's delete() method won't be called. If you need cleanup of orphaned files, you'll need to handle it yourself (for instance ... 100 ) password = forms . CharField ( widget = forms . PasswordInput ( render_value = True )) Clearable default widget for FileField ¶ Django 1.3 now includes a ClearableFileInput form widget in addition to FileInput . ClearableFileInput renders with a ch ... ... rarchy . Deleting a model doesn't delete associated files ¶ In earlier Django versions, when a model instance containing a FileField was deleted, FileField took it upon itself to also delete the file from the backend storage. This opened the door to sever ... led-back transactions and fields on different models referencing the same file. In Django 1.3, when a model is deleted the FileField 's delete() method won't be called. If you need cleanup of orphaned files, you'll need to handle it yourself (for instance ... 100 ) password = forms . CharField ( widget = forms . PasswordInput ( render_value = True )) Clearable default widget for FileField ¶ Django 1.3 now includes a ClearableFileInput form widget in addition to FileInput . ClearableFileInput renders with a ch ... ... ースノート 次のトピックへ Django 2.2.22 リリースノート 関連キーワード regression リリースノート fixes バグ 修正 Fixed saving FileField raise SuspiciousFileOperation even custom upload valid path クイック検索 Last update: 2026年10月09日 « previous | up | nex ... ... ースノート 次のトピックへ Django 3.1.10 リリースノート 関連キーワード regression リリースノート fixes バグ 修正 Fixed saving FileField raise SuspiciousFileOperation even custom upload valid path クイック検索 Last update: 2026年10月09日 « previous | up | nex ... 2026年10月08日