How to Be a Teapot in Django
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
In : from http import HTTPStatus In : HTTPStatus.IM_A_TEAPOT Out: <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.
Improve your Django develompent experience with my new book.
One summary email a week, no spam, I pinky promise.