How does Django determine if the uploaded image is valid?

I am trying to add images to my models in my Django application.

models.py

class ImageMain(models.Model):
"""This is the Main Image of the product"""
    product = models.ForeignKey(Product)
    photo = models.ImageField(upload_to='products')

In development mode, every time I try to upload an image using the Django admin, I keep getting:

Upload a valid image. The file you uploaded was either not an image or a corrupted image.

The jpg I'm trying to download can be viewed using os X Preview to make it look real.

The problem seems to be that the Python image library does not recognize it as an image. Why does this happen with a valid image?

PIL is installed, verified through the Django shell.

+3
source share
3 answers

Django. :

from PIL import Image
trial_image = Image.open(file)
trial_image.verify()

PIL.

+12

, gif png? , PIL jpeg lib . Django Ubuntu. - decoder jpeg not available, . :

$ cd libImaging
$ ./configure --with-jpeg=/somelib/lib --with-zlib=/somelib/lib
+2

Django django/forms/fields.py ImageField. Django PIL, , .

0

Source: https://habr.com/ru/post/1716704/


All Articles