Дополнение Django Middleware ломается на Heroku, но работает на локальном
У меня есть файл промежуточного ПО, который я использую для определения SIDE it, который мне нужно использовать, основываясь на среде, в которой я запускаю свое приложение.
#myusermodel/middleware.py
from django.utils.deprecation import MiddlewareMixin
from django.contrib.sites.models import Site
from django.conf import settings
class DynamicSiteMiddleware(MiddlewareMixin):
# """
# Make all domain names available through request.site
# """
def process_request(self, request):
print('I am entering the middleware')
try:
current_site = Site.objects.get(domain=request.get_host())
print('I found the site for this domain and it is', current_site)
except Site.DoesNotExist:
current_site = Site.objects.get(id=settings.SITE_ID)
print('I did not find the site for this domain so I set to the default, which is', current_site)
request.site = current_site
settings.SITE_ID = current_site.id
response = self.get_response(request)
return response
Затем я добавляю такое промежуточное ПО в свой settings.py
#mywebsite/settings.py
Все работает нормально на моем локальном сервере, но когда я перехожу на Heroku, поток обрывается с этой ошибкой mywebsite.middleware" does not define a "DynamicSiteMiddleware" attribute/class
Последние строки терминала
File "/app/.heroku/python/lib/python3.9/site-packages/django/utils/module_loading.py", line 22, in import_string
2021-11-24T15:33:40.112881+00:00 app[web.1]: raise ImportError('Module "%s" does not define a "%s" attribute/class' % (
2021-11-24T15:33:40.112881+00:00 app[web.1]: ImportError: Module "mywebsite.middleware" does not define a "DynamicSiteMiddleware" attribute/class
Почему это может происходить только на Heroky?