当前位置: 首页>>代码示例>>Python>>正文


Python Photo.get_display_url方法代码示例

本文整理汇总了Python中photologue.models.Photo.get_display_url方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.get_display_url方法的具体用法?Python Photo.get_display_url怎么用?Python Photo.get_display_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在photologue.models.Photo的用法示例。


在下文中一共展示了Photo.get_display_url方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload_image

# 需要导入模块: from photologue.models import Photo [as 别名]
# 或者: from photologue.models.Photo import get_display_url [as 别名]
def upload_image(request, upload_path=None):
    form = ImageForm(request.POST, request.FILES)
    if form.is_valid():
        image = form.cleaned_data['file']
        if image.content_type not in ['image/png', 'image/jpg', 'image/jpeg', 'image/pjpeg']:
            return HttpResponse('Bad image format')

        try:
          gallery = Gallery.objects.get(title_slug='pages_photos')
        except:
          gallery = Gallery(
                title = 'Site Pages Photos',
                title_slug = 'pages_photos',
                is_public = False,
                description = 'System album for holding images added directly to the pages',
              )
          gallery.save()


        image_name, extension = os.path.splitext(image.name)
        m = md5.new(smart_str(image_name))
        image_name = '{0}{1}'.format(m.hexdigest(), extension)

        try:
          photo = Photo(image=image, title=image_name, title_slug = slugify(image_name), caption='')
        except:
          photo = Photo(image=image_name, title_slug = slugify(image_name), caption='')

        photo.save()
        gallery.photos.add(photo)
        image_url = photo.get_display_url()

        # Original Code
        m = md5.new(smart_str(image_name))
        hashed_name = '{0}{1}'.format(m.hexdigest(), extension)
        image_path = default_storage.save(os.path.join(upload_path or UPLOAD_PATH, hashed_name), image)
       # image_url = default_storage.url(image_path)
        return HttpResponse(json.dumps({'filelink': image_url}))
    return HttpResponseForbidden()
开发者ID:simmol,项目名称:motus_website,代码行数:41,代码来源:views.py


注:本文中的photologue.models.Photo.get_display_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。