From 3fa1fe0cd6f140f5d696911198ac7d18c9346e71 Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Tue, 5 Feb 2013 16:26:07 -0500 Subject: [PATCH] change from throwing a Http404 exception, which I believe will try to render a static 404.html template - and ironically triggers a 500 server error. Just create a HttpResponse and set the status_code to 404. --- cms/djangoapps/contentstore/tests/tests.py | 3 +++ common/djangoapps/contentserver/middleware.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index 80909dad7a..085ecebff1 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -515,6 +515,9 @@ class ContentStoreTest(TestCase): # note, we know the link it should be because that's what in the 'full' course in the test data self.assertContains(resp, '/c4x/edX/full/asset/handouts_schematic_tutorial.pdf') + def test_missing_static_content(self): + resp = self.client.get("/c4x/asd/asd/asd/asd") + self.assertEqual(resp.status_code, 404) def test_capa_module(self): """Test that a problem treats markdown specially.""" diff --git a/common/djangoapps/contentserver/middleware.py b/common/djangoapps/contentserver/middleware.py index bc5d80842e..1d139bcaa0 100644 --- a/common/djangoapps/contentserver/middleware.py +++ b/common/djangoapps/contentserver/middleware.py @@ -21,7 +21,9 @@ class StaticContentServer(object): try: content = contentstore().find(loc) except NotFoundError: - raise Http404 + response = HttpResponse() + response.status_code = 404 + return response # since we fetched it from DB, let's cache it going forward set_cached_content(content)