Hey Manuel!
Image generators are used for generating PIL image objects. On the other hand,
the model fields and template tags are returning File-like objects that
represent the cached image file. These File-like objects wrap your image
generators, which they use to generate the image when needed. This separation
gives us a couple of pretty cool things. For one, we can use image generators
completely separate of the caching layer. You can think of image generators as
defining how an image is made, and the wrapper as determining when to make
the image, and how to save it.
In your case, you want to interact with a cache file, so you need to wrap your
generator with an ImageCacheFile, like this:
from imagekit.cachefiles import ImageCacheFile
image_generator = myapp_images.Thumbnail100x100(source=course_img)
result = ImageCacheFile(image_generator)
That result object is what you're expecting—a File-like object with a url
attribute.
Your code can also be simplified a little: the source kwarg that gets passed
to the image generator needs to be another File-like object. In the docs, I use
open to show one way of getting a File-like object, but you can really get it
from anywhere. In your case, it looks like you want to use an ImageField from a
model—but those are actually already File objects! So you can just do this:
from imagekit.cachefiles import ImageCacheFile
image_generator = myapp_images.Thumbnail100x100(source=course.image)
result = ImageCacheFile(image_generator)
Not only does this eliminate that extra call to open, it avoids the use of
MEDIA_ROOT, which is kind of icky here. (If you were to every change your
media storage backend, course.image would still get you the file, but using
MEDIA_ROOT like that wouldn't.)
Hope this helps!