class NamespaceMiddleware:

    def process_request(self, request):
        host = request.get_host()
parts = host.split('.')
if len(parts) >= 3:
    pass
How to use a different database per "application instance" in Django?