40👍
✅
See the documentation for ImageField.
In addition to the special attributes
that are available for FileField, an
ImageField also has height and width
attributes.
So just do the following:
<img src="{{ image.url }}" width="{{ image.width }}" height="{{ image.height }}"/>
8👍
In my case, for the width
and height
fields to work, I need to set the width_field
and height_field
of the ImageField
E.g.
class Product(models.Model):
image = models.ImageField(width_field='image_width', height_field='image_height')
image_width = models.IntegerField()
image_height = models.IntegerField()
👤Ron
- [Django]-Proper way to handle static files and templates for Django on Heroku
- [Django]-How do I add a Foreign Key Field to a ModelForm in Django?
- [Django]-Django: Make certain fields in a ModelForm required=False
Source:stackexchange.com