开发者

Djangothumbnails app issue

I an using this plugin to generate thumbnails. But somhow I couldn't make it work. The models work well, as images can be uploaded from the admin interface, even thumbnails get generated. I uploaded an image named "myphoto.jpg". The view I have is this.

def mainpage(request,slug):
    page = get_object_or_404(MainPage, slug=slug)
    image = get_object_or_404(Image)
    return direct_to_template(request, 'flatpage.html',
        extra_context={
            'page':page,
            'image':image,
        })

I have defined the class in models as "Image". I had this in the template: <img src="{% image.photo.myphoto_125x125 %}"> But the template shows error.

This is my model:

class Image(models.Model):
    title = models.CharField(max_length=100)
    photo = ImageWithThumbsField(upload_to='images/', sizes=((125,125),(200,200)))
    # second_photo = ImageWithThumbsField(upload_to='site_media/images')

    def __unicode__(self):
        return self.title

The second field, "second_photo" I have commented out as it created duplicate copy of the main image. Even I am looking 开发者_开发知识库for a way to create entry for actual unsized image in the first field itself.


I havent tried this app, but I am using PIL to create thumbnail versions of uploaded images, and using a def in the model to retrieve the path to the thumbnail for display. This may be more of a manual approach than you are looking for but it works ok for me. You can override the save method on your model (which has your FileField) or send a post_save signal to a def to create the thumbnail.

But curious to know if this app you are using adds some useful functionality over this manual approach.


Somehow I got it working. Instead of creating a separate class, I used this line photo = ImageWithThumbsField(blank=True, upload_to='images/', sizes=((125,125),(200,200))) in my blog class. And I used the line {{% post.photo.url_125x124 %} in my index.html template.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜