from django.utils.deprecation import MiddlewareMixin class FaviconMiddleware(MiddlewareMixin): def process_response(self, request, response): if 'text/html' in response.get('Content-Type', '') and b'' in response.content: icon_link = ( b"" b"\xf0\x9f\xa7\x89\">" b"\n" ) # (UTF-8 encoded 🧉 = \xf0\x9f\xa7\x89 in bytes) response.content = response.content.replace(b'', icon_link + b'') return response