fix: update existing default site in seed command instead of hardcoding 127.0.0.1

Wagtail initialises the default site with hostname 'localhost'. The previous
get_or_create on '127.0.0.1' left the localhost site intact (still pointing
to the Welcome page), so browsers got the wrong root page.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
codex_a
2026-02-28 20:30:22 +00:00
parent f6edcadd46
commit 95abbdc0ac

View File

@@ -116,15 +116,12 @@ class Command(BaseCommand):
legal_index.add_child(instance=privacy)
privacy.save_revision().publish()
site, _ = Site.objects.get_or_create(
hostname="127.0.0.1",
port=8000,
defaults={
"root_page": home,
"is_default_site": True,
"site_name": "No Hype AI",
},
)
# Update the existing default site (whatever hostname Wagtail created it with)
# rather than creating a new 127.0.0.1 entry that leaves localhost pointing
# to the Welcome page.
site = Site.objects.filter(is_default_site=True).first()
if site is None:
site = Site(hostname="localhost", port=80)
site.root_page = home
site.is_default_site = True
site.site_name = "No Hype AI"