summaryrefslogtreecommitdiff
path: root/lib/python2.7/site-packages/django/contrib/staticfiles/views.py
diff options
context:
space:
mode:
authorttt2017-05-13 00:29:47 +0530
committerttt2017-05-13 00:29:47 +0530
commitabf599be33b383a6a5baf9493093b2126a622ac8 (patch)
tree4c5ab6e0d935d5e65fabcf0258e4a00dd20a5afa /lib/python2.7/site-packages/django/contrib/staticfiles/views.py
downloadSBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.gz
SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.bz2
SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.zip
added all server files
Diffstat (limited to 'lib/python2.7/site-packages/django/contrib/staticfiles/views.py')
-rw-r--r--lib/python2.7/site-packages/django/contrib/staticfiles/views.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/python2.7/site-packages/django/contrib/staticfiles/views.py b/lib/python2.7/site-packages/django/contrib/staticfiles/views.py
new file mode 100644
index 0000000..a7f9b0d
--- /dev/null
+++ b/lib/python2.7/site-packages/django/contrib/staticfiles/views.py
@@ -0,0 +1,41 @@
+"""
+Views and functions for serving static files. These are only to be used during
+development, and SHOULD NOT be used in a production setting.
+
+"""
+import os
+import posixpath
+
+from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
+from django.http import Http404
+from django.utils.six.moves.urllib.parse import unquote
+from django.views import static
+
+from django.contrib.staticfiles import finders
+
+def serve(request, path, insecure=False, **kwargs):
+ """
+ Serve static files below a given point in the directory structure or
+ from locations inferred from the staticfiles finders.
+
+ To use, put a URL pattern such as::
+
+ (r'^(?P<path>.*)$', 'django.contrib.staticfiles.views.serve')
+
+ in your URLconf.
+
+ 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")
+ normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
+ absolute_path = finders.find(normalized_path)
+ if not absolute_path:
+ if path.endswith('/') or path == '':
+ raise Http404("Directory indexes are not allowed here.")
+ raise Http404("'%s' could not be found" % path)
+ document_root, path = os.path.split(absolute_path)
+ return static.serve(request, path, document_root=document_root, **kwargs)