gpt4 book ai didi

image - 如何在 Google App Engine 中加载 Blobproperty 图像?

转载 作者:太空宇宙 更新时间:2023-11-03 15:28:23 25 4
gpt4 key购买 nike

我写了一些代码。

我可以在 BobProperty 中保存图像。

但是我无法将图像加载到 HTML 页面中...

源代码:

类产品(db.Model):

        image = db.BlobProperty()
...

类添加:

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

product.image = db.Blob(productImage)

product.put()

但我将 {{product.image}} 写入了 html 代码。但是有像��裤 ���� ���� ���� (������������ ��(:(�������� (������ �� (��>̢���� (������>������Y������K����

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

最佳答案

我使用辅助 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

在模型中:

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)])

只需使用 {{ model.get_image_path }} 即可。

(这是 django-nonrel,但我想你可以弄清楚它的作用)

还有一个帖子 here 对这个;你应该检查一下。

关于image - 如何在 Google App Engine 中加载 Blobproperty 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4283001/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com