I am migrating from db to ndb. There is a function to dynamically serve images in a path. In DB, i pass entity key(i.key()) as img_id and using db.get(key) I get the image.
For NDB, i tried to pass key (i.key) and entity key(i.key.urlsafe()) to pass. But both these cases i get ‘unicode’ object has no attribute ‘get’ error.
**DB:**
def get(self):
image = db.get(self.request.get('img_id'))
**HTML**
<a class="post-title" href ="{{permalink}}">{{i.content}}</a>
<img src="/img?img_id={{i.key}}"></img>
**NDB**
class ImageHandler(BlogHandler):
def get(self):
img=self.request.get('img_id')
image=img.get()
if image.image:
self.response.headers['Content-Type'] = 'image/png'
self.response.out.write(image.image)
else:
self.response.out.write('No image')
I couldn’t able find the mistake in this. Am i passing wrong type for key in key.get()?
You could try the following:
HTML
NDB
Hope this helps.