Search code examples
pythondjangoimagekitdjango-imagekit

ImageKit in Django


I am implementing ImageKit in a Django app and I have everything set up properly to my knowledge. When I run the command

$python manage.py ikflush main

the command seems to run fine but nothing appears to happen. None of the images get resized or stored and cannot be accessed.

main.models.py:

class ProductImage(models.Model):
    product = models.ForeignKey(Product)
    image = models.CharField(max_length=255, null=True, blank=True)
    original = models.ImageField(upload_to='uploads/product-images/zoom/')

    class IKOptions:
        spec_module = 'main.specs'
        cache_dir = 'uploads/cache'
        image_field = 'original'

main.specs.py:

from imagekit.specs import ImageSpec 
from imagekit import processors 

class ResizeSmall(processors.Resize): 
    width = 230 
    height = 289 
    crop = False

class SmallImage(ImageSpec): 
    access_as = 'small_image' 
    pre_cache = True 
    processors = [ResizeSmall]

in template: (prints nothing)

{% for image in images %}
    {{ image.small_image }}<br />
{% endfor %}

Does anyone have any ideas on how to debug this? I really want to use ImageKit for this but I have never implemented it before. Thanks in advance!


Solution

  • Your ProductImage model needs to inherit from imagekit.models.ImageModel in instead of models.Model.