[Answer]-Maximum allowed sizes and allowed extensions of uploaded image in django?

1👍

You can check this in form clean methods:

def clean_picture(self):
    # check image weight
    image = self.cleaned_data['picture']
    if image:
        if image.width > 100:
            raise forms.ValidationError(_("Selected image is too wide"))
    return image

There is also height attribute. You can access name of the file in ImageField, get extension from it and validate it like I did with width.

👤szaman

Leave a comment