ANYONE CAN HELP ME

52 views
Skip to first unread message

arts maxwell Anderson

unread,
Apr 2, 2024, 1:20:26 PM4/2/24
to Django users
hello i have this error , i want to uppload multiple django image 
ValueError: FileInput doesn't support uploading multiple files.
any one can help me 

class FormImages(ModelForm):
    multiple_image= forms.ImageField(widget=forms.FileInput(attrs= {'multiple': True}))
   
    class Meta:
   
        model = Images
        fields=['multiple_image']


#create prodcut in function
def create_product(request):
    form_image = FormImages()
    form = FormCretaeProdcut()

    if request.method == 'POST':
        files = request.FILES.getlist('multiple_image')
        form = FormCretaeProdcut(request.POST, request.FILES)
        if form.is_valid():
            product = form.save(commit=False)
            product.save()
            product.user = request.user
            product.save()
        for file in files :
            Images.objects.create(product=product , images=file)
    else:
        form = FormCretaeProdcut()
    return render(request, 'create_product.html', {'form':form, 'i_form':form_image})    

Miroslav Milic

unread,
Apr 3, 2024, 9:12:20 AM4/3/24
to django...@googlegroups.com
Hi,

Here is the link to the Django docs where it is explained how to handle multiple file uploads with FileInput. Try to use the example from the docs as a starting point.

Best regards,
--
Miroslav Milic


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c5cf6e10-68a1-4ceb-915d-df489db9b863n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages