Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using cyclone or tornado in python, how do i make a simple handler that responds with json?

Do i do it like this?

import cyclone

class MyHandler(cyclone.web.RequestHandler):
    def get(self, command):
        details = {'status':'success'}
        json = json_encode(details)
        self.write(json)

Or is there more to it than that?

like image 659
Chris Avatar asked Jan 20 '23 02:01

Chris


1 Answers

It's even less than that: You can simply use self.write(details) if it you write a dict, it will be automatically converted to JSON.

like image 196
ThiefMaster Avatar answered Feb 15 '23 22:02

ThiefMaster