如何从Falcon主服务器文件中分离出路由?

时间:2019-04-24 10:48:23

标签: python-3.x falconframework

我想从猎鹰的主要server.py文件中分离出路由。

这是我的主文件

 try:
        import falcon, falcon_cors
        from config.config import server_config
        from resources.pingserver import Ping
    except ImportError as err:
        raise err

    salescoachbot= falcon.API()

这是我的资源文件

class Ping(object):

    def on_get(self, req, resp):
        msg = 'Falcon GET service is working'
        resp.body = json.dumps(msg, ensure_ascii=False)
        resp.status = falcon.HTTP_200

    def on_post(self, req, resp):
        msg = 'Falcon POST service is working'
        resp.body = json.dumps(msg, ensure_ascii=False)
        resp.status = falcon.HTTP_200

现在,如何添加将所有资源配置为api的路由文件,而不是这样做。

try:
    import falcon, falcon_cors
    from config.config import server_config
    from resources.pingserver import Ping
except ImportError as err:
    raise err

salescoachbot= falcon.API()
salescoachbot.add_route('/ping', Ping())

0 个答案:

没有答案