upload_to for ImageField changes name of file being uploaded

44 Aufrufe
Direkt zur ersten ungelesenen Nachricht

bradford li

ungelesen,
29.01.2015, 03:35:2229.01.15
an django...@googlegroups.com
I posted a question on stackoverflow regarding my issue:


Basically upload_to value will change my ImageField.name to the upload_to value

bradford li

ungelesen,
03.02.2015, 02:22:1303.02.15
an django...@googlegroups.com
There is bounty on this stackoverflow question is anyone is interested

Tom Evans

ungelesen,
03.02.2015, 07:23:2403.02.15
an django...@googlegroups.com
On Tue, Feb 3, 2015 at 7:22 AM, bradford li <bradf...@gmail.com> wrote:
> There is bounty on this stackoverflow question is anyone is interested
>

It looks like it has already been answered multiple times - you cannot
upload a file in to a subdirectory of MEDIA_ROOT and have its name
attribute be the base file name. The name attribute of a FileField is
the path to the file relative to MEDIA_ROOT*. If you want to store
files in subfolders of MEDIA_ROOT, then obviously, the name attribute
will not consist of just the file name of the uploaded file.

If you want to know or use the name of the file, use
os.path.basename() on the name attribute.

Cheers

Tom

* This isn't actually true, but is close enough to the truth as makes
no difference. It is in fact relative to whatever "storage engine"
that FileField uses; the default storage engine behaves as I have
described.
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten