2011-04-02 12 views

Respuesta

27

Consulte la documentación para ImageField.

Además de los atributos especiales que están disponibles para FileField, un ImageField también tiene altura y anchura atributos.

Así que haga lo siguiente:

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

hmmm .. no funciona en mi extremo. '{% con tan post.postimage_set.all imagen%}' ' {{ alt }}' '{ % endwith%}' –

2

En mi caso, por los width y height campos para trabajar, necesito establecer el width_field y height_field del ImageField

P. ej

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