访问Django模板中ImageField上的图像尺寸? [英] Accessing image dimensions on an ImageField in a Django template?

查看:441
本文介绍了访问Django模板中ImageField上的图像尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型中有 ImageField ,我可以在模板中显示图像。但是,如何检索图像的高度和宽度?

I have ImageField in my model and I'm able to display the image in a template. However, how do I retrieve the image's height and width?

推荐答案

请参阅 ImageField


除了可用于FileField的特殊属性
之外,
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 }}"/>

这篇关于访问Django模板中ImageField上的图像尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆