2011-04-02 58 views

回答

27

請參閱ImageField的文檔。

除了可用於FileField字段的特殊屬性 ,一個 ImageField的也具有高度和寬度 屬性。

因此,只要做到以下幾點:

<img src="{{ image.url }}" width="{{ image.width }}" height="{{ image.height }}"/> 
+0

嗯..它不工作在我的最後。 '{%與post.postimage_set.all作爲圖像%}' ''{{ alt }} '{%ENDWITH%}' – 2013-10-03 11:57:07

2

在我的情況下,爲widthheight下地幹活,我需要設置的ImageField

例如在width_fieldheight_field

class Product(models.Model): 
    image = models.ImageField(width_field='image_width', height_field='image_height') 
    image_width = models.IntegerField() 
    image_height = models.IntegerField()