In this case the blob is an an image, which is great. Just use images.get_serving_url(blob_key) and you're happy. I've used this function, and trust me, it is awesome for serving images. Just append =sxx to the url where xx is the pixel size you want. It automatically resizes the image and serves it.
If the blob isn't an image, then you're out of luck w.r.t an easy way out. Maybe use the BlobReader to make a string representation and output it?
If it isn't an image or text, though, what could you possibly want to write to HTML?
编写一个自定义模板标记/模板过滤器,用于获取 blob 数据并生成适当的 数据 URL,它将直接在您生成的 HTML 文档中对图像数据进行编码。
然后,在您的模板中,您将显示如下所示的图像:
这将在模板中产生如下输出:
There isn't a built-in template tag for displaying arbitrary data like that. I can think of two approaches:
Write a request handler for serving avatars as images. Based on your example, request handler would just need to look up the greeting to get the image data, send an appropriate Content-Type: image/jpeg (or image/png or whatever) header and then write the blob data to the response stream.
Then, in your template, you'd display the image like this:
Write a custom template tag/template filter that takes the blob data and generates an appropiate data URL, which would encode the image data directly in the HTML document you're generating.
Then, in your template, you'd display the image something like this:
<img src="{{ greeting.avatar|dataurl }}">
which would result in output along these lines in the template:
发布评论
评论(2)
在这种情况下,斑点是一个图像,这很棒。只需使用
images.get_serving_url(blob_key)
你很高兴。我已经使用过这个功能,相信我,它对于提供图像来说非常棒。只需将=sxx
附加到网址,其中xx
是您想要的像素大小。它会自动调整图像大小并提供服务。如果斑点不是图像,那么您就没有简单的解决办法了。也许可以使用
BlobReader
来制作一个字符串表示并输出它?但是,如果它不是图像或文本,您可能想向 HTML 写入什么内容?
In this case the blob is an an image, which is great. Just use
images.get_serving_url(blob_key)
and you're happy. I've used this function, and trust me, it is awesome for serving images. Just append=sxx
to the url wherexx
is the pixel size you want. It automatically resizes the image and serves it.If the blob isn't an image, then you're out of luck w.r.t an easy way out. Maybe use the
BlobReader
to make a string representation and output it?If it isn't an image or text, though, what could you possibly want to write to HTML?
没有用于显示此类任意数据的内置模板标记。我可以想到两种方法:
编写一个请求处理程序,将头像作为图像提供服务。根据您的示例,请求处理程序只需要查找问候语即可获取图像数据,发送适当的
Content-Type: image/jpeg
(或image/png
或其他)标头,然后将 blob 数据写入响应流。然后,在您的模板中,您将显示如下图像:
编写一个自定义模板标记/模板过滤器,用于获取 blob 数据并生成适当的 数据 URL,它将直接在您生成的 HTML 文档中对图像数据进行编码。
然后,在您的模板中,您将显示如下所示的图像:
这将在模板中产生如下输出:
There isn't a built-in template tag for displaying arbitrary data like that. I can think of two approaches:
Write a request handler for serving avatars as images. Based on your example, request handler would just need to look up the greeting to get the image data, send an appropriate
Content-Type: image/jpeg
(orimage/png
or whatever) header and then write the blob data to the response stream.Then, in your template, you'd display the image like this:
Write a custom template tag/template filter that takes the blob data and generates an appropiate data URL, which would encode the image data directly in the HTML document you're generating.
Then, in your template, you'd display the image something like this:
which would result in output along these lines in the template: