Wednesday, 11 September 2013

resize image in the views and load it in the templates in django

resize image in the views and load it in the templates in django

Is there any possible way to resize the original image in the views.py and
then load the resized image from the views to the template? I tried using
sorl-thumbnail and easy_thumbnail, they works great, but I don't know why,
somehow whenever I upload it using the apache server, the server only
loads the images uploaded by the django's inbuilt server, and when I load
the page again with the django's inbuilt server it loads the uploaded
image nicely. So, is there anyway that I can resize the image in the views
itself, and then load it in the templates? And if there is, please kindly
guide me how do I do it. Thank you!
models.py
class Status(models.Model):
status = models.TextField()
image = ImageField(upload_to=get_upload_file_name, blank=True)
pub_date = models.DateTimeField(default=datetime.now)
creator = models.ForeignKey(User, related_name="creator_set")
likes = models.ManyToManyField(User, through="Like")
class Meta:
ordering = ['-pub_date']
verbose_name_plural = ('Status')
def __unicode__(self):
return self.status

No comments:

Post a Comment