Click here to Skip to main content
15,883,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900