from django_middleware_global_request import get_request from django.contrib import messages import logging def __getattr__(name): def wrapper(*args, **kwargs): request = get_request() getattr(logging, name, logging.info)(*args) return getattr(messages, name)(request, *args, **kwargs) if hasattr(messages, name): return wrapper raise AttributeError(f"'{__name__}' object has no attribute '{name}'")