python - How to return a json response in twisted? -


when using django: do

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

how can in twisted? official document not this.

document here

only serving wsgi applications can set mimetype.but want process , post there no more example, , searched nothing found.

from twisted.web import resource class mygreatresource(resource.resource):     def render_get(self, request):         return "xxxx" 

it return raw string

encoded json is (byte) string.

if question "how set content-type of response application/json?" answer is:

request.responseheaders.addrawheader(b"content-type", b"application/json") 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -