如何在Django管理面板中显示多个图像

时间:2013-06-07 13:23:25

标签: python django

我正在使用它在我的Django管理面板中显示图像,但有没有显示多个图像的方法:

def product_Image(self):
    """Method to return store image for admin panel"""

    return '<img src="/images/%s" height="150" width="150"/>' % self.image_paths
product_Image.allow_tags = True

但如果self.image_paths包含图片路径列表:["full/1182_Garishma1.jpg","full/K-Yukta-A.jpg"] 那么我如何在django管理面板中显示所有图像...

2 个答案:

答案 0 :(得分:1)

你不能先在路径上循环吗?

def product_Image(self):
    """Method to return store image for admin panel"""

    images = ''
    for image_path in self.image_paths:
        images += '<img src="/images/%s" height="150" width="150"/>' % image_path

    return images

答案 1 :(得分:1)

试试这个:

def product_Image(self):
    """Method to return store image for admin panel"""

    images = ''
    for image_path in self.image_paths:
        images += '<img src="/images/%s" height="150" width="150"/>' % image_path            
    return images
product_Image.allow_tags = True
没有product_Image.allow_tags = True图片的

将不会显示...