The docs for django.core.files.File imply I can do this: print File(open(path)).url but the File object has no attribute ‘url’ However, django.db.models.fields.files.FieldFile extends File and does have all the attributes described in the docs for File, but I can’t create one without giving it a model field.
All I want it something that does what the docs for django.core.files.File (link above) say it does, take a python file and give it attributes like ‘url’ and ‘path’ and ‘name’, can anyone help?
Cheers, Jake
Regardless of what the Django doc says, if you look at the code for the File class, I don’t see it there. Following Ignacio’s suggestion, you can derive from the Django
Fileand use the MEDIA_ROOT and MEDIA_URL settings to implement the property you’re looking for…