本文介绍了如何在Google App Engine中加载Blobproperty图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我写了一些代码。

我可以将图像保存到BobProperty中。

但我无法加载图像进入HTML页面...

源代码:

class Product(db.Model):

  image = db.BlobProperty()
...

class add:

preroduct_mage = self.request.get(' image')

product.image = db.Blob(productImage)

product.put()

但我将{{product.image}}写入html代码。但有像 袀 ( (:( ( ( >̢ ( > Y K ׏



我应该怎么做,如果我想从数据存储加载图像?

解决方案

我使用辅助视图:

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

response = HttpResponse(image)
response ['Content-Type'] =image / png
response ['Cache-Control'] =max-age = 7200
返回回应

以及在模型中:

  def get_image_path(self):
#这将返回serve_image的url,以及image的pk参数。
#类似于/ main / serve_image / 1231234dfg22;这个网址将会返回一个
#的响应图像和blob
return reverse(main.views.serve_image,args = [str(self.pk)])

只需使用 {{model.get_image_path}}



(这是django-nonrel,但我想你可以找出它的作用)



另外,还有一篇文章关于此;你应该检查出来。


I wrote some codes.

I could save image in BobProperty.

But I cannot load image into HTML page...

source code:

class Product(db.Model):

        image = db.BlobProperty()
            ...

class add:

  productImage = self.request.get('image')

  product.image = db.Blob(productImage)

  product.put()

but i wrote {{product.image}} into html code. But there were like ��袀 ���� ���� ���� (����������� ��(:(������� (������� (��>̢��� (�������>������Y������K��׏

What should i do if i want load image from datastore?

解决方案

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.

这篇关于如何在Google App Engine中加载Blobproperty图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:58