4👍
✅
Adding my comment as a proper answer:
Please try adding enctype= multipart/form-data
to your <form>
element in your template file.
If you don’t have this element your request.FILES
will always be empty.
Copying from https://docs.djangoproject.com/en/1.7/topics/http/file-uploads/#basic-file-uploads:
Note that
request.FILES
will only contain data if the request method wasPOST
and the<form>
that posted the request has the attributeenctype="multipart/form-data"
. Otherwise,request.FILES
will be empty.
1👍
If the field is required in your models.py
(i.e. you have not stated blank=True
or null=True
), and you are using a ModelForm
, then that will be a required field in your ModelForm
Source:stackexchange.com