django - sorl-thumbnail not save cache -
i used sorl-thumbnail. when viewed modern template, path /media/cache/25/b8/25b8886a95680ecb25d29cf67f4ba131.jpg displayed , thumbnail image not saved. mysetting
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) templates_dirs = (os.path.join(base_dir,'templates'),) debug = true template_debug = true thumbnail_debug = true allowed_hosts = [] installed_apps = [ .... 'django.contrib.staticfiles', 'blog', 'sorl.thumbnail', ] # static files (css, javascript, images) # https://docs.djangoproject.com/en/1.10/howto/static-files/ base_dir = os.path.dirname(os.path.abspath(__file__)) static_url = '/static/' static_root = os.path.join(base_dir,'static') media_url = '/media/' media_root = os.path.join(base_dir,'/media')
from django import models form sorlthumbnail import imagefield class post(models.model): author = models.foreignkey('auth.user') title = models.charfield(max_length=200) class postimage(models.model): def image_path(self,filename): ruta = "postimage/%s/%s" % (self.picture,str(filename)) return ruta post = models.foreignkey('blog.post',related_name='image_set') picture = models.imagefield(upload_to=image_path) def __unicode__(self): return self.picture class meta: verbose_name = "con" verbose_name_plural = "config"
mytempleat
{% load thumbnail %} {%block content%} {% thumbnail post.image_set.all "40x40" crop="80% top" im %} <div> <img src="{{ im.url }}"> </div> {% endthumbnail %} {% image in post.image_set.all %} {% thumbnail post.image_set.all "50x100" im %} <img src ="{{im.url}}" > {% endthumbnail %} {% endfor %} </div> {%endblock%}
Comments
Post a Comment