Given is on gae using tipfy (python) the following model:
greeting.avatar = db.Blob(avatar)
What is the template-tag to display a blob (here image)?
Given is on gae using tipfy (python) the following model:
greeting.avatar = db.Blob(avatar)
What is the template-tag to display a blob (here image)?
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:
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?