Skip to content

Instantly share code, notes, and snippets.

@adi-
adi- / common.py
Last active April 14, 2023 09:29
Django middleware to send broken links to logger (vs standard send broken link by mail)
```
Django sends broken links by mail using built in middleware "BrokenLinkEmailsMiddleware".
This class alters that functionality and sends broken links to logger.
```
class BrokenLinkLogMiddleware(BrokenLinkEmailsMiddleware):
def process_response(self, request, response):
"""Log broken link for relevant 404 NOT FOUND responses."""
if response.status_code == 404 and not settings.DEBUG: