def get(self, **kwargs):
     ident = kwargs['id']        
     post = BlogPost.get_by_id(ident)
     
     self.response.headers.add_header('Content-Type', 'application/json; charset=utf-8')
     self.write( json.dumps( post.to_json() ) )            
     
示例#2
0
    def get(self, **kwargs):
        ident = kwargs['id']
        
        post = memcache.get(POST_KEY % ident)
        t = memcache.get(POST_TIME_KEY % ident)
        
        if not post or not t:
            post = BlogPost.get_by_id(ident)
            t = time.time()
            memcache.set(POST_KEY % ident, post)
            memcache.set(POST_TIME_KEY % ident, t)

        t = int (time.time() - t)
        
        if not post:
            error = 'No such post'
            self.render_post(error=error)
        else:
            self.render_post(post = post, post_generated = t)