Opened 6 years ago

Closed 5 years ago

#11597 closed (fixed)

Documentation for File object is misleading

Reported by: amenasse@… Owned by: nobody
Component: Documentation Version: master
Severity: Keywords: File url path
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I found the documentation for the File object misleading.


If you need to construct a File yourself, the easiest way is to create one using a Python built-in file object:

>>> from django.core.files import File

# Create a Python file object using open()
>>> f = open('/tmp/', 'w')
>>> myfile = File(f)

Now you can use any of the File attributes and methods documented in The File object."

The last statement is misleading because i found i couldn't:

describes attributes such as url and path available to a File object

 >>> myfile.url
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'File' object has no attribute 'url'
>>> myfile.path
Traceback (most recent call last):
  File "<console>", line 1, in <module>


i'm using svn release and docs.

as a side note , it would be really nice if things did work the way i understood from the docs.

My particular case requires me to create a File object that is not tied to a database field but has path and url attributes just like a FileField so from the templates i can do:

{{ object.url }}

For now i am hacking around this with my own class that provides these methods.

 class FakeFileField(object):
     def __init__(self,path): = FileSystemStorage()
       self._path = path

     def _get_url(self):

    def _get_path(self):



Change History (3)

comment:1 Changed 6 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 6 years ago by timo

Looks to me like the documentation is incorrect and that path and url are actually attributes on django.db.models.fields.FileField and not django.core.files.File

comment:3 Changed 5 years ago by gabrielhurley

  • Resolution set to fixed
  • Status changed from new to closed

(In [14834]) [1.2.X] Fixed #13162 and #11597 -- Improved the file handling documentation: Removed documentation of methods on django.core.files.File that did not exist, added documentation for undocumented methods and attributes that did exist, did a general cleanup of the text and organization, and added more metadata targets. Thanks to amenasse and for the reports.

Backport of [14833] from trunk.

Note: See TracTickets for help on using tickets.
Back to Top