1👍
To upload a file, you need to add enctype='multipart/form-data'
to your HTML form. So your form should look like:
<form method="POST" action="" enctype='multipart/form-data'>
{% csrf_token %}
<input type="submit"></input>
{{ form }}
</form>
and in your views, you need to access request.FILES
to get the uploaded file. Your upload image view should be:
def uploadImageView(request):
form = UploadImageForm(request.POST or None, request.FILES or None)
if request.method == 'POST':
if form.is_valid():
form.save()
# rest of the code.
- [Django]-Django – Display an image with static files
- [Django]-Resizing uploaded files in django using PIL
Source:stackexchange.com