0

我想要python中的REST API。发出请求时,我想要所有列表而不是个人名称。当请求是/getgamebyid/999时,我得到{“name”:“third one”,“release_date”:“2013 -10-28", "id": 999} 但我想获得所有三个名字?我该怎么办?

from datetime import date
import tornado.escape
import tornado.ioloop
import tornado.web

class VersionHandler(tornado.web.RequestHandler):
    def get(self):
        response = { 'version': '3.5.1',
                     'last_build':  date.today().isoformat() }
        self.write(response)

class GetGameByIdHandler(tornado.web.RequestHandler):
    def get(self, id):
        response = { 'id': int(id),
                     'name': 'Crazy Game',
                     'release_date': date.today().isoformat(),
                                          'id': int(id),
                     'name': 'Second one',
                     'release_date': date.today().isoformat(),
                      'id': int(id),
                     'name': 'third one',
                     'release_date': date.today().isoformat() }

        self.write(response)


application = tornado.web.Application([
    (r"/getgamebyid/([0-9]+)", GetGameByIdHandler),
    (r"/version", VersionHandler)
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()
4

0 回答 0