
On 2025-08-01 01:37, Mark Sapiro wrote:
raise self.model.DoesNotExist( django.contrib.sites.models.Site.DoesNotExist: Site matching query does not exist.
That error will occur when settings.py contains
SITE_ID = 0
and the host in the http request is not one of the hosts in the django_site table in the database or in Sites in the Django admin web UI. Is that possibly the case here?
The SITE_ID and database table check okay. The SITE_ID is supposed to be "0"? No?
SITE_ID Test server - settings.py: SITE_ID = 0 Prod server - settings.py: SITE_ID = 0
HTTP_HOST
Test server DB - mailmanweb.django_site table: domain and name fields OK
Prod server DB - mailmanweb.django_site table: domain and name fields
OK
And the hosts are displayed in Sites in the admin UI.
I also checked the ALLOWED_HOSTS in the Test and Prod servers. Both have:
... "localhost", "127.0.0.1", "<IP4 ADDRESS OF HOST>", "<MY.DOMAIN.COM>" "<OTHER.DOMAINNAME.COM>", ...
Is there a complete traceback preceding the log snippet you report. If so, what is it?
The traceback does suggest that the SITE does not exist...
======================= TRACEBACK =====================
Traceback (most recent call last): File "/opt/mailman/venv/lib/python3.11/site-packages/django/contrib/sites/models.py", line 39, in _get_site_by_request SITE_CACHE[host] = self.get(domain__iexact=host) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/db/models/query.py", line 637, in get raise self.model.DoesNotExist( django.contrib.sites.models.Site.DoesNotExist: Site matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "/opt/mailman/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner response = get_response(request) ^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/postorius/views/list.py", line 1158, in list_index return render( ^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/shortcuts.py", line 24, in render content = loader.render_to_string(template_name, context, request, using=using) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/template/loader.py", line 62, in render_to_string return template.render(context, request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/template/backends/django.py", line 61, in render return self.template.render(context) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/template/base.py", line 173, in render with context.bind_template(self): File "/usr/lib/python3.11/contextlib.py", line 137, in __enter__ return next(self.gen) ^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/template/context.py", line 254, in bind_template updates.update(processor(self.request)) ^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django_mailman3/context_processors.py", line 32, in common context["site_name"] = get_current_site(request).name ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/contrib/sites/shortcuts.py", line 16, in get_current_site return Site.objects.get_current(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/contrib/sites/models.py", line 61, in get_current return self._get_site_by_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/contrib/sites/models.py", line 45, in _get_site_by_request SITE_CACHE[domain] = self.get(domain__iexact=domain) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/db/models/manager.py", line 87, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/mailman/venv/lib/python3.11/site-packages/django/db/models/query.py", line 637, in get raise self.model.DoesNotExist( django.contrib.sites.models.Site.DoesNotExist: Site matching query does not exist. ERROR 2025-08-01 05:21:46,176 2030595 django.request Internal Server Error: /owa/auth/logon.aspx ERROR 2025-08-01 05:21:46,176 2030595 django.request Internal Server Error: /owa/auth/logon.aspx
============= END TRACEBACK =================
... -- "whatever is proxying to Django setting the appropriate HTTP_HOST header." -- which I don't understand.
This is in the configuration of the web server. It should be configured to pass the host of the incoming request to the proxy target in the HTTP_HOST header. In nginx this is
proxy_set_header Host $host;
. In apache it isProxyPreserveHost On
, but again the change to user_adapter shouldn't affect this.
That all looks good for both the Prod and Test servers.
... location /static/ { alias /opt/mailman/web/static/; }
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
...