1
0
mirror of https://github.com/django/django.git synced 2025-10-28 08:06:09 +00:00

Fixed #20819 -- Return 404 instead of 500 error when `staticfiles` view is used in production.

This commit is contained in:
Tai Lee
2013-07-31 17:11:49 +10:00
parent 5154c9f92c
commit 4c6ffcf721
4 changed files with 16 additions and 6 deletions

View File

@@ -11,7 +11,6 @@ except ImportError: # Python 2
from urllib import unquote
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.http import Http404
from django.views import static
@@ -31,9 +30,7 @@ def serve(request, path, insecure=False, **kwargs):
It uses the django.views.static view to serve the found files.
"""
if not settings.DEBUG and not insecure:
raise ImproperlyConfigured("The staticfiles view can only be used in "
"debug mode or if the --insecure "
"option of 'runserver' is used")
raise Http404
normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
absolute_path = finders.find(normalized_path)
if not absolute_path: