简体   繁体   中英

Redirect request to different Resource(Falcon)

I am using Python3.4 and Falcon1.0 . I want to redirect request to another resource in falcon API.

For example, I have 2 resources:

class Res1(object):
    def on_get(self, req, resp):
        print("I'm on resource 1")
        resp.status = falcon.HTTP_200

class Res2(object):
    def on_get(self, req, resp):
        print("I'm on resource 2")
        resp.status = falcon.HTTP_200

And API URL format is localhost/{id} . I want to call Res1 if id is 1 else Res2 .

exception falcon.HTTPMovedPermanently(location)

你可以试试看或解释更多

您最好将逻辑放在python函数中,然后根据您的任何API中的else条件调用该函数,这是一种可重用和松散耦合的方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM