コード例 #1
0
ファイル: views.py プロジェクト: timothyclemans/djangocg
def serve(request, path, document_root=None, 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>.*)$', 'djangocg.contrib.staticfiles.views.serve')

    in your URLconf.

    It uses the djangocg.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 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)
コード例 #2
0
ファイル: findstatic.py プロジェクト: timothyclemans/djangocg
 def handle_label(self, path, **options):
     verbosity = int(options.get('verbosity', 1))
     result = finders.find(path, all=options['all'])
     path = smart_text(path)
     if result:
         if not isinstance(result, (list, tuple)):
             result = [result]
         output = '\n  '.join(
             (smart_text(os.path.realpath(path)) for path in result))
         self.stdout.write("Found '%s' here:\n  %s" % (path, output))
     else:
         if verbosity >= 1:
             self.stderr.write("No matching file found for '%s'." % path)