Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fixed #20819 -- Return 404 instead of 500 error when ``staticfiles`` vie... #1416

Merged
merged 1 commit into from 9 months ago

2 participants

Tai Lee Jannis Leidel
Tai Lee

...w is used in production.

docs/releases/1.6.txt
... ...
@@ -812,6 +812,14 @@ Miscellaneous
812 812
 * :meth:`~django.core.validators.validate_email` now accepts email addresses
813 813
   with ``localhost`` as the domain.
814 814
 
  815
+* :view:`~django.contrib.staticfiles.views.serve` will now raise an
1
Jannis Leidel Owner
jezdez added a note July 31, 2013

master is not going to be 1.6, but 1.7, can you move this section in the other release notes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
docs/ref/contrib/staticfiles.txt
... ...
@@ -344,7 +344,8 @@ This view function serves static files in development.
344 344
 
345 345
 .. warning::
346 346
 
347  
-    This view will only work if :setting:`DEBUG` is ``True``.
  347
+    This view will only work if :setting:`DEBUG` is ``True``. Otherwise, it will
  348
+    raise the :exc:`~django.http.Http404` exception.
1
Jannis Leidel Owner
jezdez added a note July 31, 2013

Can you add a .. versionchanged:: 1.7 here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Jannis Leidel jezdez merged commit 0674b38 into from July 31, 2013
Jannis Leidel jezdez closed this July 31, 2013
Tai Lee mrmachine deleted the branch February 05, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 31, 2013
Fixed #20819 -- Return 404 instead of 500 error when ``staticfiles`` …
…view is used in production.
4c6ffcf
This page is out of date. Refresh to see the latest.
5  django/contrib/staticfiles/views.py
@@ -11,7 +11,6 @@
11 11
     from urllib import unquote
12 12
 
13 13
 from django.conf import settings
14  
-from django.core.exceptions import ImproperlyConfigured
15 14
 from django.http import Http404
16 15
 from django.views import static
17 16
 
@@ -31,9 +30,7 @@ def serve(request, path, insecure=False, **kwargs):
31 30
     It uses the django.views.static view to serve the found files.
32 31
     """
33 32
     if not settings.DEBUG and not insecure:
34  
-        raise ImproperlyConfigured("The staticfiles view can only be used in "
35  
-                                   "debug mode or if the --insecure "
36  
-                                   "option of 'runserver' is used")
  33
+        raise Http404
37 34
     normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
38 35
     absolute_path = finders.find(normalized_path)
39 36
     if not absolute_path:
6  docs/ref/contrib/staticfiles.txt
@@ -350,6 +350,12 @@ This view function serves static files in development.
350 350
     **insecure**. This is only intended for local development, and should
351 351
     **never be used in production**.
352 352
 
  353
+.. versionchanged:: 1.7
  354
+
  355
+    Will now raise an :exc:`~django.http.Http404` exception instead of
  356
+    :exc:`~from django.core.exceptions.ImproperlyConfigured` when
  357
+    :setting:`DEBUG` is ``True``.
  358
+
353 359
 .. note::
354 360
 
355 361
     To guess the served files' content types, this view relies on the
8  docs/releases/1.7.txt
@@ -122,6 +122,14 @@ Miscellaneous
122 122
 * Loading empty fixtures emits a ``RuntimeWarning`` rather than raising
123 123
   :class:`~django.core.management.CommandError`.
124 124
 
  125
+* :view:`~django.contrib.staticfiles.views.serve` will now raise an
  126
+  :exc:`~django.http.Http404` exception instead of
  127
+  :exc:`~from django.core.exceptions.ImproperlyConfigured` when :setting:`DEBUG`
  128
+  is ``True``. This change removes the need to conditionally add the view to
  129
+  your root URLconf, which in turn makes it safe to reverse by name. It also
  130
+  removes the ability for visitors to generate spurious HTTP 500 errors by
  131
+  requesting static files that don't exist or haven't been collected yet.
  132
+
125 133
 Features deprecated in 1.7
126 134
 ==========================
127 135
 
3  tests/staticfiles_tests/tests.py
@@ -650,8 +650,7 @@ def setUp(self):
650 650
         settings.DEBUG = False
651 651
 
652 652
     def test_disabled_serving(self):
653  
-        six.assertRaisesRegex(self, ImproperlyConfigured, 'The staticfiles view '
654  
-            'can only be used in debug mode ', self._response, 'test.txt')
  653
+        self.assertFileNotFound('test.txt')
655 654
 
656 655
 
657 656
 class TestServeStaticWithDefaultURL(TestServeStatic, TestDefaults):
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.