Ticket #1013: index-dot-html.diff

File index-dot-html.diff, 1.6 KB (added by richie@…, 10 years ago)

Patch for django/views/static.py

  • django/views/static.py

     
    77from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect
    88from django.core.template import Template, Context, TemplateDoesNotExist
    99
    10 def serve(request, path, document_root=None, show_indexes=False):
     10def serve(request, path, document_root=None, show_indexes=False, default=''):
    1111    """
    1212    Serve static files below a given point in the directory structure.
    1313
     
    1919    also set ``show_indexes`` to ``True`` if you'd like to serve a basic index
    2020    of the directory.  This index view will use the template hardcoded below,
    2121    but if you'd like to override it, you can create a template called
    22     ``static/directory_index``.
     22    ``static/directory_index``.  To use a file as the directory index, set
     23    ``default`` to the filename to use (eg. ``index.html``).
    2324    """
    2425
    2526    # Clean up given path to only allow serving files below document_root.
     
    3738        newpath = os.path.join(newpath, part).replace('\\', '/')
    3839    if newpath and path != newpath:
    3940        return HttpResponseRedirect(newpath)
    40     fullpath = os.path.join(document_root, newpath)
     41    fullpath = os.path.join(document_root, newpath)
     42    if os.path.isdir(fullpath) and default:
     43        defaultpath = os.path.join(fullpath, default)
     44        if os.path.exists(defaultpath):
     45            fullpath = defaultpath
    4146    if os.path.isdir(fullpath):
    4247        if show_indexes:
    4348            return directory_index(newpath, fullpath)
Back to Top