HttpResponse vs. Render

I looked through some code and came up with this question - Django: What is the difference b / w HttpResponse vs HttpResponseRedirect vs render_to_response - which discusses different types of response to a request.

Is there any reason to use HttpResponse over render ? If so, what will be the precedent and advantage of this? Thanks.

+7
source share
2 answers

render used for what the name is already indicated: to create a template file (mostly html, but can be of any format). render is basically a simple wrapper around HttpResponse that displays a template, although as said in a previous answer, you can use HttpResponse to return other things in the response, and not just to create templates.

+7
source

Of course, let's say you make an AJAX call and want to return a JSON object:

 return HttpResponse(jsonObj, mimetype='application/json') 

The accepted answer in the original question refers to this method.

+4
source

All Articles