开发者

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 = F开发者_JAVA技巧alse

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!


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


This may just be a formatting mistake in the question and not in your code. But IKOptions should be nested in your model class:

class ProductImage(models.Model):
    # fields, etc...
    class IKOptions:
        # ...

Also, before you run ikflush, did you add ImageKit to INSTALLED_APPS in your settings file?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜