How to load Blobproperty image in Google App Engine?

社会主义新天地 提交于 2019-11-29 07:42:30

I use an auxiliary view:

def serve_image(request, image):
    if image == "None":
        image = ""

    response = HttpResponse(image)
    response['Content-Type'] = "image/png"
    response['Cache-Control'] = "max-age=7200"
    return response

and in the model:

def get_image_path(self):
    # This returns the url of serve_image, with the argument of image's pk.
    # Something like /main/serve_image/1231234dfg22; this url will return a
    # response image with the blob
    return reverse("main.views.serve_image", args=[str(self.pk)])

and just use {{ model.get_image_path }} instead.

(this is django-nonrel, but I guess you could figure out what it does)

Also, there is a post here about this; you should check it out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!