Django: unable to bind uploaded image to form ImageField ()

here is my problem i created this form:

class SettingsForm(forms.Form): ... logo = forms.ImageField() ... 

The download is great and I managed to display the image, but I can’t snap it to the form. Here is what I did:

 data = ... files = {'logo': SimpleUploadedFile('logo.jpg', logo.read())} form = SettingsForm(data=data, files=files) 

The logo object is ImageFieldFile . I tested the read method in the shell, this is normal. I have no warnings displaying this page, only "no files selected."

Thank you for your help. Sorry for the format of this post, I'm new to stackoverflow and django.

+4
source share
1 answer

I'm not sure about this, but according to the django documentation, in the binding forms, the data and files are not kwargs, but are args, so try the following:

 form = SettingsForm(data, files) 
+1
source

All Articles