Marco Florian
Marco Florian

Reputation: 969

How to specify an "upload to" path in a Form File Field in Django?

I'm not using a Model for this form, I know I can set the upload_to parameter inside a Model File Field, but seems not possible from the Form.

When I set the FileField the file is uploaded to the MEDIA_ROOT I setup on my settings. Although, I would like the file uploaded to /folder. Is it possible directly from the Form File Field or I must move the file manually?

Upvotes: 1

Views: 3696

Answers (2)

rasool badashiani
rasool badashiani

Reputation: 1

You have to actually create your ImageField in Django models then inherit from the model into your form

Upvotes: 0

HassenPy
HassenPy

Reputation: 2103

You will have to process the file manually from request.FILES['formfieldname'] , this should provide a clear description for both cases (using the FileField in your model or manual handling from the request):
https://docs.djangoproject.com/en/1.8/topics/http/file-uploads/#basic-file-uploads

Upvotes: 2

Related Questions