2007-10-14 12:10:02 +08:00
|
|
|
"""
|
2007-11-30 13:14:09 +08:00
|
|
|
Views and functions for serving static files. These are only to be used
|
2007-10-14 12:10:02 +08:00
|
|
|
during development, and SHOULD NOT be used in a production setting.
|
|
|
|
"""
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
import mimetypes
|
2005-09-26 02:45:01 +08:00
|
|
|
import os
|
|
|
|
import posixpath
|
2006-03-03 12:53:04 +08:00
|
|
|
import re
|
|
|
|
import stat
|
2006-05-02 09:31:56 +08:00
|
|
|
import urllib
|
2010-10-20 09:33:24 +08:00
|
|
|
import warnings
|
2007-10-31 11:59:40 +08:00
|
|
|
from email.Utils import parsedate_tz, mktime_tz
|
2005-09-26 02:45:01 +08:00
|
|
|
|
2007-10-14 12:10:02 +08:00
|
|
|
from django.template import loader
|
|
|
|
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified
|
|
|
|
from django.template import Template, Context, TemplateDoesNotExist
|
2007-10-31 11:59:40 +08:00
|
|
|
from django.utils.http import http_date
|
2007-10-14 12:10:02 +08:00
|
|
|
|
2010-10-20 09:33:24 +08:00
|
|
|
from django.contrib.staticfiles.views import \
|
|
|
|
directory_index, was_modified_since, serve as staticfiles_serve
|
|
|
|
|
|
|
|
|
2005-09-26 02:45:01 +08:00
|
|
|
def serve(request, path, document_root=None, show_indexes=False):
|
|
|
|
"""
|
|
|
|
Serve static files below a given point in the directory structure.
|
2005-11-07 05:54:37 +08:00
|
|
|
|
|
|
|
To use, put a URL pattern such as::
|
|
|
|
|
2005-09-26 21:38:49 +08:00
|
|
|
(r'^(?P<path>.*)$', 'django.views.static.serve', {'document_root' : '/path/to/my/files/'})
|
2005-11-07 05:54:37 +08:00
|
|
|
|
|
|
|
in your URLconf. You must provide the ``document_root`` param. You may
|
2005-09-26 02:45:01 +08:00
|
|
|
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
|
2008-12-05 03:33:28 +08:00
|
|
|
``static/directory_index.html``.
|
2005-09-26 02:45:01 +08:00
|
|
|
"""
|
2010-10-20 09:33:24 +08:00
|
|
|
warnings.warn("The view at `django.views.static.serve` is deprecated; "
|
|
|
|
"use the path `django.contrib.staticfiles.views.serve` "
|
|
|
|
"instead.", PendingDeprecationWarning)
|
|
|
|
return staticfiles_serve(request, path, document_root, show_indexes)
|