widgets.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:django-content-gallery 作者: Kemaweyan 项目源码 文件源码
def render(self, name, value, attrs=None):
        """
        Renders custom widget with the image preview for uploaded images
        or the default widget if the image has not yet been uploaded.
        """
        # if the image is uploaded, the 'image' argument
        # is an instance of GalleryImageFieldFile
        if isinstance(value, fields.GalleryImageFieldFile):
            # get image data
            data = utils.create_image_data(value)
            # fill the template and replace the default one
            self.template_with_initial = self.template.format(
                settings.CONF['preview_width'] + 14,
                settings.CONF['preview_height'] + 14,
                settings.CONF['preview_width'],
                settings.CONF['preview_height'],
                settings.CONF['preview_height'],
                html.escape(json.dumps(data)),
                utils.create_static_url("content_gallery/img/zoom.png"),
                settings.CONF['preview_width'] - 55
            )
        # render the widget
        return super().render(name, value, attrs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号