Django: how to be a teapot

HTCPCP, or Hyper Text Coffee Pot Control Protocol, was published as an April Fool’s joke 24 years ago today. It’s an HTTP extension for controlling coffee pots, and whilst it is a joke, it appears in various places around the web.
HTCPCP adds one HTTP response code, “418 I’m a teapot”, which teapots can respond with if they are asked to brew coffee. As a registered status code, it has even made its way into the Python standard library’s HTTPStatus:
In [1]: from http import HTTPStatus
In [2]: HTTPStatus.IM_A_TEAPOT
Out[2]: <HTTPStatus.IM_A_TEAPOT: 418>
You can use HTTPStatus with Django to create a teapot page on your site. This will let you follow Google’s google.com/teapot page, so you can be one step closer to web scale!
Throw a view in your project like:
from http import HTTPStatus
from django.shortcuts import render
def teapot(request):
return render(
request,
"teapot.html",
status=HTTPStatus.IM_A_TEAPOT,
)
Add a URL definition, such as at teapot/, and make a snazzy template. For a demo, I downloaded a sweet teapot GIF from gifcities.org:

Great. That will be very useful, I’m sure.
😸😸😸 Check out my new book on using GitHub effectively, Boost Your GitHub DX! 😸😸😸
One summary email a week, no spam, I pinky promise.
Related posts:
- How to Add a Favicon to Your Django Site
- Announcing WhiteNoise 6
- Django: introducing django-browser-reload, for automatically refreshing your browser during development
Tags: django