0Pricing
Django Academy · Lesson

Status Codes and HttpResponse Subclasses

Use JsonResponse, redirects, and 404 helpers.

Status Codes and HttpResponse Subclasses is a free Django Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Django Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

What Status Codes Mean

Every response carries a status code. The number tells the browser if things went well, moved, or broke. 🚦

The Friendly 2xx Codes

Codes in the 2xx range mean success. 200 is the everyday OK, and 201 signals that something new was created.

Redirects in the 3xx Range

A 3xx code tells the browser to go elsewhere. 301 is a permanent move, while 302 is a temporary redirect.

Client Errors: 4xx

The 4xx codes blame the request. 404 means not found, 403 means forbidden, and 400 means a bad request.

JsonResponse for APIs

Use JsonResponse to send data as JSON. Pass a dict and Django sets the right content type for you.

return JsonResponse({"name": "Ada"})

Redirecting with redirect

The redirect shortcut returns a 302 to another URL or view name, so users land exactly where you want them.

return redirect('home')

HttpResponseRedirect

Behind redirect sits HttpResponseRedirect. Give it a URL and it builds the 302 response for you directly.

return HttpResponseRedirect('/login/')

Permanent Redirects

For a permanent move, use HttpResponsePermanentRedirect, which sends a 301 so browsers remember the new address.

Raising a 404

Raise Http404 when a record is missing. Django catches it and shows your not-found page with a 404 code.

raise Http404("No such post")

get_object_or_404

The get_object_or_404 helper fetches a row or raises Http404 automatically, saving you a manual check.

post = get_object_or_404(Post, pk=3)

Pick the Right Subclass

Choosing the right subclass sets a correct status with no manual numbers, keeping your views clear and honest.

Quick Check

Which response sends JSON with the correct content type?

Recap: Speak in Codes

Status codes and HttpResponse subclasses like JsonResponse, redirect, and Http404 let your views answer clearly. 🚀

Frequently asked questions

Is the “Status Codes and HttpResponse Subclasses” lesson free?

Yes — the full text of “Status Codes and HttpResponse Subclasses” is free to read here on the web, and the Django Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Django Academy course, upgrade to CoddyKit PRO.

What will I learn in “Status Codes and HttpResponse Subclasses”?

Use JsonResponse, redirects, and 404 helpers. You practise Django Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Django Academy?

No prior experience is required. Django Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Status Codes and HttpResponse Subclasses” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Django Academy lesson?

Yes. Every Django Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

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