I am rendering a list of instances, each with a binary blob image, in a template. To render the images, I need to encode them with base64. I'm not sure how to encode each image in a loop, my code below doesn't work. I'm also not sure if passing the list of objects and the list of encoded images to render_template
increases network traffic. How do I correctly encode a list of images, and is this efficient?
class A:
number = ndb.IntegerProperty()
image = ndb.BlobProperty()
@app.route('/show-all')
def show_all():
all = A.query().order(A.number).fetch()
encoded_images = [b64encode(image) for all.image in all] # Doesn't work
return make_response(render_template("template.html", title="A", objects=all, images=encoded_images))