def serve(request, path, document_root=None, show_indexes=False, default='<STR_LIT>'):
<EOL>path = posixpath.normpath(unquote(path))<EOL>path = path.lstrip('<STR_LIT:/>')<EOL>newpath = '<STR_LIT>'<EOL>for part in path.split('<STR_LIT:/>'):<EOL><INDENT>if not part:<EOL><INDENT>continue<EOL><DEDENT>drive, part = os.path.splitdrive(part)<EOL>head, part = os.path.split(part)<EOL>if part in (os.curdir, os.pardir):<EOL><INDENT>continue<EOL><DEDENT>newpath = os.path.join(newpath, part).replace('<STR_LIT:\\>', '<STR_LIT:/>')<EOL><DEDENT>if newpath and path != newpath:<EOL><INDENT>return HttpResponseRedirect(newpath)<EOL><DEDENT>fullpath = os.path.join(document_root, newpath)<EOL>if os.path.isdir(fullpath) and default:<EOL><INDENT>defaultpath = os.path.join(fullpath, default)<EOL>if os.path.exists(defaultpath):<EOL><INDENT>fullpath = defaultpath<EOL><DEDENT><DEDENT>if os.path.isdir(fullpath):<EOL><INDENT>if show_indexes:<EOL><INDENT>return directory_index(newpath, fullpath)<EOL><DEDENT>raise Http404("<STR_LIT>")<EOL><DEDENT>if not os.path.exists(fullpath):<EOL><INDENT>raise Http404('<STR_LIT>' % fullpath)<EOL><DEDENT>statobj = os.stat(fullpath)<EOL>mimetype = mimetypes.guess_type(fullpath)[<NUM_LIT:0>] or '<STR_LIT>'<EOL>if not was_modified_since(request.META.get('<STR_LIT>'),<EOL>statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):<EOL><INDENT>if django.VERSION > (<NUM_LIT:1>, <NUM_LIT:6>):<EOL><INDENT>return HttpResponseNotModified(content_type=mimetype)<EOL><DEDENT>else:<EOL><INDENT>return HttpResponseNotModified(mimetype=mimetype)<EOL><DEDENT><DEDENT>contents = open(fullpath, '<STR_LIT:rb>').read()<EOL>if django.VERSION > (<NUM_LIT:1>, <NUM_LIT:6>):<EOL><INDENT>response = HttpResponse(contents, content_type=mimetype)<EOL><DEDENT>else:<EOL><INDENT>response = HttpResponse(contents, mimetype=mimetype)<EOL><DEDENT>response["<STR_LIT>"] = http_date(statobj[stat.ST_MTIME])<EOL>response["<STR_LIT>"] = len(contents)<EOL>return response<EOL>
Serve static files below a given point in the directory structure.

To use, put a URL pattern such as::

    (r'^(?P<path>.*)$', 'django.views.static.serve',
        {'document_root' : '/path/to/my/files/'})

in your URLconf. You must provide the ``document_root`` param. You may
also set ``show_indexes`` to ``True`` if you'd like to serve a basic index
of the directory.  This index view will use the template hardcoded below,
but if you'd like to override it, you can create a template called
``static/directory_index.html``.

 Modified by ticket #1013 to serve index.html files in the same manner
 as Apache and other web servers.

 https://code.djangoproject.com/ticket/1013