About Pinged Pages and HEAD Request

If you use UptimeRobot, Oh Dear, PingPing, or other service to monitor your website's uptime, make sure to handle the HEAD requests for the pinged page early in the view, so that you don't load any unnecessary queries and don't render the templates for it:

1
2
3
4
5
6
7
8
from django.shortcuts import render
from django.http import HttpResponse

def home(request, *args, **kwargs):
    if request.method == "HEAD":
        return HttpResponse()
    context = {...}
    return render(request, "startpage/index.html", context)

Tips and Tricks Dev Ops Development Django 5.x Django 4.2 Django 3.2