SoFunction
Updated on 2024-12-19

django request return different types of images json,xml,html example

The main way django returns data is with the HttpResponse in the

I'll just post the code for the specifics

from  import HttpResponse
### Quote
def index(request):
 if ["type"] == "img":
  return HttpResponse(open("","rb"),content_type="image/png")
  ## Here to return to the picture ##
 elif ["type"] == "html":
  return HttpResponse(open("","rb"),content_type="text/html")
  ## Return html text
 elif ["type"] == "xml":
  return HttpResponse(open("","rb"),content_type="text/xml")
  ## Return xml text
 elif ["type"] == "json":
  return HttpResponse({"code":"ok"},content_type="application/json")
  ## Return json text
 
from  import JsonResponse
def index(request):
 
 return JsonResponse({"code":"ok"})
 ## Here.JsonResponse It's even easier to return thejson 

Above this django request to return different types of images json,xml,html example is all I have shared with you, I hope to be able to give you a reference, and I hope you support me more.