Returning an HttpResponse
Build a response and set its status and headers.
Every View Returns One
A view must return an HttpResponse. Django sends that object to the browser, so returning it is not optional. 📤
from django.http import HttpResponseThe Simplest Response
Pass a string to HttpResponse and Django sends it as the page body. That string becomes what the browser shows.
def hi(request):
return HttpResponse("Hello!")All lessons in this course
- How a Request Reaches Your View
- The HttpRequest Object
- Returning an HttpResponse
- Status Codes and HttpResponse Subclasses