I’m getting started with Google App Engine. I want to make AJAX chat like Twitter.
class ChatMessage(db.Model):
message = db.StringProperty()
created = db.DateTimeProperty(auto_now=True)
Server JSON encodes the response,
class RPCHandler(webapp.RequestHandler):
def get(self):
chat_list = {'message':'Hello!'}
self.response.out.write(simplejson.dumps(chat_list))
Result: Hello!
This is OK. But replace RPCHandler
class RPCHandler(webapp.RequestHandler):
def get(self):
newchat = ChatMessage(message="Hi!")
newchat.put()
que = db.Query(ChatMessage).order('-created')
chat_list = que.fetch(limit=1)
self.response.out.write(simplejson.dumps(chat_list))
Result: Error. The server is not accessible (get)
How can I JSON encode Entities?
In App Engine Python you can use this script to encode db.Models to JSON. You may have to customize some parts, like the DateTime formatting.
http://code.google.com/p/google-app-engine-samples/source/browse/trunk/geochat/json.py?r=55