web.py seeother() 未按预期运行

问题描述 投票:0回答:1

我是 web.py 的新手。尝试按照文档中的说明设置重定向。但是,当我发送

localhost:8080/health/
的卷曲请求时,应用程序返回
None
而不是
HAPPY

import web

urls = (
        #url, #class_name
        '/', 'index',
        '/(.*)/', 'redirect',   # match localhost:port/somepath/
        '/health', 'health'
)


class index:
    def GET(self):
        return 'Hello World!'

# this is faulty and not redirecting as expected
class redirect:
    def GET(self, path):
        web.seeother('/' + path)

class health:
    def GET(self):
        return "HAPPY"

if __name__ == "__main__":
    app = web.application(urls, globals())
    app.run()
python web.py
1个回答
0
投票

你的Python代码没问题。问题是你使用了curl。

默认情况下,除非另有指示,否则curl不会遵循重定向。添加 -L 选项就可以了。

$ curl -L http://localhost:8080/health
HAPPY
© www.soinside.com 2019 - 2024. All rights reserved.