Skip to content

Commit cdfb12e

Browse files
committed
Emit a more helpful error if INERTIA_LAYOUT is unset
1 parent dafda82 commit cdfb12e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

inertia/http.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from json import dumps as json_encode
44

55
import requests
6+
from django.core.exceptions import ImproperlyConfigured
67
from django.http import HttpResponse
78
from django.template.loader import render_to_string
89

@@ -127,10 +128,19 @@ def build_merge_props(self):
127128
def build_first_load(self, data):
128129
context, template = self.build_first_load_context_and_template(data)
129130

131+
try:
132+
layout = settings.INERTIA_LAYOUT
133+
if not layout:
134+
raise AttributeError("INERTIA_LAYOUT is set, but has a falsy value")
135+
except AttributeError as ae:
136+
raise ImproperlyConfigured(
137+
"INERTIA_LAYOUT must be set in your Django settings"
138+
) from ae
139+
130140
return render_to_string(
131141
template,
132142
{
133-
"inertia_layout": settings.INERTIA_LAYOUT,
143+
"inertia_layout": layout,
134144
**context,
135145
},
136146
self.request,

inertia/tests/test_rendering.py

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from django.core.exceptions import ImproperlyConfigured
2+
from django.test import override_settings
13
from pytest import warns
24

35
from inertia.test import InertiaTestCase, inertia_div, inertia_page
@@ -245,3 +247,13 @@ def test_merge_props_are_not_included_when_reset(self):
245247
},
246248
),
247249
)
250+
251+
252+
class MisconfiguredLayoutTestCase(InertiaTestCase):
253+
def test_with_props(self):
254+
with override_settings(INERTIA_LAYOUT=None):
255+
with self.assertRaisesMessage(
256+
ImproperlyConfigured,
257+
"INERTIA_LAYOUT must be set",
258+
):
259+
self.client.get("/props/")

0 commit comments

Comments
 (0)