Django Upload multiple files without using Django forms or models

689 views
Skip to first unread message

Sam W

unread,
Apr 14, 2019, 10:25:30 AM4/14/19
to Django users
I want to upload multiple files to the system (Local folder) without using Django forms or models. For a single file, everything works just fine and the file get saved to a local media folder under the project. But when I changed the function from {request.FILES['images'] } To {request.FILES.getlist('images')} to be able to upload multiple images I didn't get any error at all, but no images saved !! 

 I have a simple html form:
{ <form method="post" id="submitimg" enctype="multipart/form-data" name="images">
            {% csrf_token %}
            <label>Choose Images</label>
            <input type="file" name="images[]" id="imgs" multiple >
            <input type="submit" name="submit" value="UPLOAD"/>
</form> }

Python function:
{
  def uploadmulti(request):
        if request.method == 'POST' and request.FILES.getlist('images'):
            files = request.FILES.getlist('images')
            fs = FileSystemStorage()

            filename = fs.save(files.name, files 
            file_url = fs.url(filename)
            return render(request, 'home.html', {
                'file_url':file_url
        })
        return render(request, 'upmulti.html') 
}

I know I'm missing something!!! 

Thank you

christophe szczepanski

unread,
May 13, 2019, 11:00:24 AM5/13/19
to Django users
do solved your problem ? , i have the same ?

Thank you :)

Sam W

unread,
May 13, 2019, 2:30:14 PM5/13/19
to Django users
Reply all
Reply to author
Forward
0 new messages