Ticket #1013: index-dot-html.diff
File index-dot-html.diff, 1.6 KB (added by , 19 years ago) |
---|
-
django/views/static.py
7 7 from django.utils.httpwrappers import HttpResponse, HttpResponseRedirect 8 8 from django.core.template import Template, Context, TemplateDoesNotExist 9 9 10 def serve(request, path, document_root=None, show_indexes=False ):10 def serve(request, path, document_root=None, show_indexes=False, default=''): 11 11 """ 12 12 Serve static files below a given point in the directory structure. 13 13 … … 19 19 also set ``show_indexes`` to ``True`` if you'd like to serve a basic index 20 20 of the directory. This index view will use the template hardcoded below, 21 21 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``). 23 24 """ 24 25 25 26 # Clean up given path to only allow serving files below document_root. … … 37 38 newpath = os.path.join(newpath, part).replace('\\', '/') 38 39 if newpath and path != newpath: 39 40 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 41 46 if os.path.isdir(fullpath): 42 47 if show_indexes: 43 48 return directory_index(newpath, fullpath)