I'm trying to remove the clear checkbox in Django's ImageField and remove the displayed current value of the file. Tha approach I tried is to replace the widget as proposed here How to not render django image field currently and clear stuff? but the result is that I get ValidationError :
"Upload a valid image. The file you uploaded was either not an image or a corrupted image.". Though the validation error the image get's uploaded, but I do not get redirected to the success page and an error is being rendered in the form.
What's the recommended way to remove the current value in the ImageField?
Deal with django ImageField current value displayed in forms
342 Views Asked by Zarrie At
1
A solution that works for me, though I'm not sure how good is it.
profile_picture = forms.FileField(label='Upload profile picture', widget=forms.FileInput,validators=[validators.validate_image_file_extension], required=False)I replaced
ImageFieldwithFileFieldand then added theImageFielddefault validator withFileInputwidget and then added'accept': 'image/*'to that widget, so the select shows only images. In this way I mimic the ImageField, but no error occurs.