views.py 文件源码

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

项目:django-imperavi-widget 作者: dzaytsev91 项目源码 文件源码
def uploaded_images_json(request, upload_path=None):
    upload_path = upload_path or UPLOAD_PATH
    results = list()
    path = os.path.join(settings.MEDIA_ROOT, upload_path)
    if os.path.isdir(path):
        for image in os.listdir(path):
            image_path = '{0}{1}'.format(path, smart_str(image))
            if not os.path.isdir(image_path) and imghdr.what(image_path):
                thumb = get_thumbnail(image_path, '100x74', crop='center')
                image_url = os.path.join(settings.MEDIA_URL, upload_path, image)
                results.append({'thumb': thumb.url, 'image': image_url})
        return HttpResponse(json.dumps(results))
    return HttpResponse('{}')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号