I have a regular pattern; where I want to log a bit more detail on an issue - but show the user not much more than an opaque ‘Not Found’ (and certainly not reflect entered values back).
E.g.
def view_foobar(request, node=None, tag=None):
try:
machines = Machine.objects.filter(something...
except ObjectDoesNotExist:
logger.error("Node {} not found .....
return HttpResponse("Not found", status=404, content_type="text/plain")
Which then in the logs yields something such as
2025-01-04 10:23:34,068 [ERROR] acl.views: Node XXX not found....
2025-01-04 10:23:34,072 [WARNING] django.request: Not Found: /acl/api/v1/getok/spacedeur
With the second Warning coming from BaseHandler (django/core/handlers/base.py) its get_response() method that calls log_response().
How does one best suppress this second warning / overwrite that method narrowly for just cases like this. But still keep the ability to do rich/complex HttpResponse() and so on / not recreate most of HttpResponse (or raise NotFound; etc) ? And without fiddling with the log level ideally ?