繁体   English   中英

如何返回扭曲的json响应?

[英]How to return a json response in twisted?

当我使用django时:我总是这样做

return HttpResponse(json.dumps(result), mimetype='application/json')

我该如何扭曲呢? 官方文件不说这个。

在这里记录

只有Serving WSGI Applications可以设置mimetype 。但是我想处理GET和POST没有更多示例了,我没有找到任何搜索结果。

from twisted.web import resource
class MyGreatResource(resource.Resource):
    def render_GET(self, request):
        return "xxxx"

返回原始字符串

编码的JSON 一个(字节)字符串。

如果您的问题是“如何将响应的Content-Type设置为application/json ?” 那么答案是:

request.responseHeaders.addRawHeader(b"content-type", b"application/json")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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