如何为 class 中的一种方法关闭 cherrypy.tools.json_out()?
How to switch cherrypy.tools.json_out() off for one method in class?
我有一个 CherryPy 服务回复 json 响应。为此,我在 class.
的顶部实现了 @cherrypy.tools.json_out()
装饰器
我现在 class 中有一种方法需要用图像进行响应。
该方法设置了cherrypy.response.headers['Content-Type']
对应的图片mime-type。如果 tools.json_out() 装饰器在我的代码中,它就不起作用。没有装饰器它就可以工作(但我需要以不同的方式实现所有其他方法)。
我尝试在 CherryPy 的配置中关闭 tools.json_out()
并在方法上使用装饰器,但这并没有否决它。
我的方法有什么问题?
谢谢指点。
我想我找到了...
抱歉发得太早了。
实际上我首先在错误的地方添加了否决 @cherrypy.config(**{'tools.json_out.on': False})
的装饰器。
它需要放在方法的其他装饰器前面(@myservice.expose
在我的代码中)。
现在可以了。
希望此信息对以后的其他人有所帮助。
我有一个 CherryPy 服务回复 json 响应。为此,我在 class.
的顶部实现了@cherrypy.tools.json_out()
装饰器
我现在 class 中有一种方法需要用图像进行响应。
该方法设置了cherrypy.response.headers['Content-Type']
对应的图片mime-type。如果 tools.json_out() 装饰器在我的代码中,它就不起作用。没有装饰器它就可以工作(但我需要以不同的方式实现所有其他方法)。
我尝试在 CherryPy 的配置中关闭 tools.json_out()
并在方法上使用装饰器,但这并没有否决它。
我的方法有什么问题?
谢谢指点。
我想我找到了... 抱歉发得太早了。
实际上我首先在错误的地方添加了否决 @cherrypy.config(**{'tools.json_out.on': False})
的装饰器。
它需要放在方法的其他装饰器前面(@myservice.expose
在我的代码中)。
现在可以了。
希望此信息对以后的其他人有所帮助。