From c7b997bd02e06f02362de098958b6a1b9c0023f5 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Tue, 3 Jun 2014 11:50:38 +0100 Subject: [PATCH] When previewing a page creation, populate url_path. This ensures that Page.dummy_request can infer a sensible hostname rather than falling back on example.com, which fails when ALLOWED_HOSTS is enforced. --- wagtail/wagtailadmin/views/pages.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wagtail/wagtailadmin/views/pages.py b/wagtail/wagtailadmin/views/pages.py index 308f6fdd4..17717dbba 100644 --- a/wagtail/wagtailadmin/views/pages.py +++ b/wagtail/wagtailadmin/views/pages.py @@ -349,6 +349,10 @@ def preview_on_create(request, content_type_app_name, content_type_model_name, p if form.is_valid(): form.save(commit=False) + # ensure that our unsaved page instance has a suitable url set + parent_page = get_object_or_404(Page, id=parent_page_id).specific + page.set_url_path(parent_page) + # This view will generally be invoked as an AJAX request; as such, in the case of # an error Django will return a plaintext response. This isn't what we want, since # we will be writing the response back to an HTML page regardless of success or