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

发布于 2024-10-05 02:08:03 字数 519 浏览 0 评论 0原文

我写了一些代码。

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

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

源代码:

class Product(db.Model):

        image = db.BlobProperty()
            ...

class add:

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

  product.image = db.Blob(productImage)

  product.put()

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小草泠泠 2024-10-12 02:08:03

我使用辅助视图:

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,但我想您可以弄清楚它的作用)

另外,还有一篇文章 这里 关于这一点;你应该检查一下。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文