Hello All,
I am very new to Django and I already have a working code for uploading multiple files. The problem I am having is that when I hit the upload button, it takes me to another page. How can I make it to stay at the page where the upload button is clicked. Also, I would a conformational message to display when the button is click and would like it to be display on the same page I am uploading the files.
Thanks a lot for the help in advance
What I have tried:
views.py:
def Upload(request):
dir_path = '/Users/x/Desktop/myproject/myproject/media'
for count, file in enumerate(request.FILES.getlist('files')):
def process(f):
with open(dir_path + '/file_' + str(count) , 'wb+') as destination:
for chunk in f.chunks():
destination.write(chunk)
process(f)
return HttpResponse("myapp/list.html", str(count+1)+" File(s) uploaded!")
home.html:
<form action="{% url "UploadFile" %}" method="post" enctype="multipart/form-data">
<input type="file" name="files" multiple/>
<input type="submit" value="Upload" />
</form>