0PricingLogin
Django Academy · Lesson

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 HttpResponse

The 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

  1. How a Request Reaches Your View
  2. The HttpRequest Object
  3. Returning an HttpResponse
  4. Status Codes and HttpResponse Subclasses
← Back to Django Academy