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

What can cause "Required Package 'IndyCore' not found" when compiling a Delphi 2010 project? -

Change the color of an oval at click in Java AWT -