I want to send image src to browser with AJAX.
Server side:
que = db.Query(Imageitem).order('-created')
item_list = que.fetch(limit=1)
if(len(item_list)>0):
itemkey = {'imgid':item_list[0].key()}
else:
itemkey = {'imgid':''}
json_itemkey = gaejsonEncoder.encode(itemkey)
Client side template:
<img src='img?img_id=$(.imgid)'></img>
I use SNBinder for client side binding and $(.imgid) means itemkey[0].imgid.
But this is error.
datastore_types.Key.from_path(u'Imageitem', 515L, _app=u'fileshare')
is not JSON serializable
Is there any way to send the key for datastore entity to client side?
Any advice greatly appreciated.
If you want to JSON encode a key item, just use the string version of the key by passing the key to str():