首页 > 解决方案 > python tornado框架中传递URL的问题

问题描述

我正在传递资源路径,如下所示。

application = tornado.web.Application(handlers=[ (r"/rsgateway/data/json/eventstore/subscriber/orderid/555555&xyz=1", getUsageHistory),)

在资源路径中,我需要传递 URL。但是由于像 +,$ 这样的特殊字符,我的脚本没有返回 output 。需要知道如何在资源路径中传递 url。

标签: pythontornado

解决方案


您应该在处理程序中接收请求参数。您的代码可能如下所示:

应用程序:

application = tornado.web.Application(handlers=[
(r"/rsgateway/data/json/eventstore/subscriber/orderid/([0-9]+)", UsageHistory),
])

和处理程序:

class UsageHistory(RequestHandler):
    async def get(self, order_id: str):
        xyz = self.request.query_arguments.get('xyz')
        data = await self.orders.get_history(int(order_id), xyz)
        await self.finish(escape.json_encode(data))

推荐阅读