GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Saturday, April 16, 2011

Django - Custom Response

HttpResponse is the basic for manipulating response to client.
For displaying an xml file, use
response = HttpResponse(mimetype="text/xml")
response.write('<?xml version="1.0"?>')
response.write('<data>No Data</data>')
return response

For displaying image, use
im = Image.open("nature.png")   # use PIL library
response = HttpResponse(mimetype="image/png")
im.save(response, "PNG")
return response
Share/Bookmark

No comments:

Post a Comment