Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixes #15270 -- Moved back the serve view to django.views.static due …

…to dependency conflicts with the contrib app staticfiles (reverts parts of r14293). Added a helper function that generates URL patterns for serving static and media files during development. Thanks to Carl for reviewing the patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15530 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a26034ffbf8951276b79ccb298423bc809246637 1 parent 6b1191b
Jannis Leidel authored February 14, 2011
26  django/conf/urls/static.py
... ...
@@ -0,0 +1,26 @@
  1
+import re
  2
+from django.conf import settings
  3
+from django.conf.urls.defaults import patterns, url
  4
+from django.core.exceptions import ImproperlyConfigured
  5
+
  6
+def static(prefix, view='django.views.static.serve', **kwargs):
  7
+    """
  8
+    Helper function to return a URL pattern for serving files in debug mode.
  9
+
  10
+    from django.conf import settings
  11
+    from django.conf.urls.static import static
  12
+
  13
+    urlpatterns = patterns('',
  14
+        # ... the rest of your URLconf goes here ...
  15
+    ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  16
+
  17
+    """
  18
+    if not settings.DEBUG:
  19
+        return []
  20
+    elif not prefix:
  21
+        raise ImproperlyConfigured("Empty static prefix not permitted")
  22
+    elif '://' in prefix:
  23
+        raise ImproperlyConfigured("URL '%s' not allowed as static prefix" % prefix)
  24
+    return patterns('',
  25
+        url(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, **kwargs),
  26
+    )
24  django/contrib/staticfiles/urls.py
... ...
@@ -1,28 +1,16 @@
1  
-import re
2 1
 from django.conf import settings
3  
-from django.conf.urls.defaults import patterns, url, include
4  
-from django.core.exceptions import ImproperlyConfigured
  2
+from django.conf.urls.static import static
5 3
 
6 4
 urlpatterns = []
7 5
 
8  
-# only serve non-fqdn URLs
9  
-if settings.DEBUG:
10  
-    urlpatterns += patterns('',
11  
-        url(r'^(?P<path>.*)$', 'django.contrib.staticfiles.views.serve'),
12  
-    )
13  
-
14 6
 def staticfiles_urlpatterns(prefix=None):
15 7
     """
16 8
     Helper function to return a URL pattern for serving static files.
17 9
     """
18  
-    if not settings.DEBUG:
19  
-        return []
20 10
     if prefix is None:
21 11
         prefix = settings.STATIC_URL
22  
-    if not prefix or '://' in prefix:
23  
-        raise ImproperlyConfigured(
24  
-            "The prefix for the 'staticfiles_urlpatterns' helper is invalid.")
25  
-    if prefix.startswith("/"):
26  
-        prefix = prefix[1:]
27  
-    return patterns('',
28  
-        url(r'^%s' % re.escape(prefix), include(urlpatterns)),)
  12
+    return static(prefix, view='django.contrib.staticfiles.views.serve')
  13
+
  14
+# Only append if urlpatterns are empty
  15
+if settings.DEBUG and not urlpatterns:
  16
+    urlpatterns += staticfiles_urlpatterns()
153  django/contrib/staticfiles/views.py
@@ -3,27 +3,21 @@
3 3
 development, and SHOULD NOT be used in a production setting.
4 4
 
5 5
 """
6  
-import mimetypes
7 6
 import os
8 7
 import posixpath
9  
-import re
10  
-import stat
11 8
 import urllib
12  
-from email.Utils import parsedate_tz, mktime_tz
13 9
 
14 10
 from django.conf import settings
15 11
 from django.core.exceptions import ImproperlyConfigured
16  
-from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified
17  
-from django.template import loader, Template, Context, TemplateDoesNotExist
18  
-from django.utils.http import http_date
  12
+from django.http import Http404
  13
+from django.views import static
19 14
 
20  
-from django.contrib.staticfiles import finders, utils
  15
+from django.contrib.staticfiles import finders
21 16
 
22  
-
23  
-def serve(request, path, document_root=None, show_indexes=False, insecure=False):
  17
+def serve(request, path, document_root=None, insecure=False, **kwargs):
24 18
     """
25 19
     Serve static files below a given point in the directory structure or
26  
-    from locations inferred from the static files finders.
  20
+    from locations inferred from the staticfiles finders.
27 21
 
28 22
     To use, put a URL pattern such as::
29 23
 
@@ -31,135 +25,14 @@ def serve(request, path, document_root=None, show_indexes=False, insecure=False)
31 25
 
32 26
     in your URLconf.
33 27
 
34  
-    If you provide the ``document_root`` parameter, the file won't be looked
35  
-    up with the staticfiles finders, but in the given filesystem path, e.g.::
36  
-
37  
-    (r'^(?P<path>.*)$', 'django.contrib.staticfiles.views.serve', {'document_root' : '/path/to/my/files/'})
38  
-
39  
-    You may also set ``show_indexes`` to ``True`` if you'd like to serve a
40  
-    basic index of the directory.  This index view will use the
41  
-    template hardcoded below, but if you'd like to override it, you can create
42  
-    a template called ``static/directory_index.html``.
  28
+    It automatically falls back to django.views.static
43 29
     """
44 30
     if not settings.DEBUG and not insecure:
45  
-        raise ImproperlyConfigured("The view to serve static files can only "
46  
-                                   "be used if the DEBUG setting is True or "
47  
-                                   "the --insecure option of 'runserver' is "
48  
-                                   "used")
49  
-    if not document_root:
50  
-        path = os.path.normpath(path)
51  
-        absolute_path = finders.find(path)
52  
-        if not absolute_path:
53  
-            raise Http404('"%s" could not be found' % path)
  31
+        raise ImproperlyConfigured("The staticfiles view can only be used in "
  32
+                                   "debug mode or if the the --insecure "
  33
+                                   "option of 'runserver' is used")
  34
+    normalized_path = posixpath.normpath(urllib.unquote(path)).lstrip('/')
  35
+    absolute_path = finders.find(normalized_path)
  36
+    if absolute_path:
54 37
         document_root, path = os.path.split(absolute_path)
55  
-    # Clean up given path to only allow serving files below document_root.
56  
-    path = posixpath.normpath(urllib.unquote(path))
57  
-    path = path.lstrip('/')
58  
-    newpath = ''
59  
-    for part in path.split('/'):
60  
-        if not part:
61  
-            # Strip empty path components.
62  
-            continue
63  
-        drive, part = os.path.splitdrive(part)
64  
-        head, part = os.path.split(part)
65  
-        if part in (os.curdir, os.pardir):
66  
-            # Strip '.' and '..' in path.
67  
-            continue
68  
-        newpath = os.path.join(newpath, part).replace('\\', '/')
69  
-    if newpath and path != newpath:
70  
-        return HttpResponseRedirect(newpath)
71  
-    fullpath = os.path.join(document_root, newpath)
72  
-    if os.path.isdir(fullpath):
73  
-        if show_indexes:
74  
-            return directory_index(newpath, fullpath)
75  
-        raise Http404("Directory indexes are not allowed here.")
76  
-    if not os.path.exists(fullpath):
77  
-        raise Http404('"%s" does not exist' % fullpath)
78  
-    # Respect the If-Modified-Since header.
79  
-    statobj = os.stat(fullpath)
80  
-    mimetype, encoding = mimetypes.guess_type(fullpath)
81  
-    mimetype = mimetype or 'application/octet-stream'
82  
-    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
83  
-                              statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):
84  
-        return HttpResponseNotModified(mimetype=mimetype)
85  
-    contents = open(fullpath, 'rb').read()
86  
-    response = HttpResponse(contents, mimetype=mimetype)
87  
-    response["Last-Modified"] = http_date(statobj[stat.ST_MTIME])
88  
-    response["Content-Length"] = len(contents)
89  
-    if encoding:
90  
-        response["Content-Encoding"] = encoding
91  
-    return response
92  
-
93  
-
94  
-DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
95  
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
96  
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
97  
-  <head>
98  
-    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
99  
-    <meta http-equiv="Content-Language" content="en-us" />
100  
-    <meta name="robots" content="NONE,NOARCHIVE" />
101  
-    <title>Index of {{ directory }}</title>
102  
-  </head>
103  
-  <body>
104  
-    <h1>Index of {{ directory }}</h1>
105  
-    <ul>
106  
-      {% ifnotequal directory "/" %}
107  
-      <li><a href="../">../</a></li>
108  
-      {% endifnotequal %}
109  
-      {% for f in file_list %}
110  
-      <li><a href="{{ f|urlencode }}">{{ f }}</a></li>
111  
-      {% endfor %}
112  
-    </ul>
113  
-  </body>
114  
-</html>
115  
-"""
116  
-
117  
-def directory_index(path, fullpath):
118  
-    try:
119  
-        t = loader.select_template(['static/directory_index.html',
120  
-                'static/directory_index'])
121  
-    except TemplateDoesNotExist:
122  
-        t = Template(DEFAULT_DIRECTORY_INDEX_TEMPLATE, name='Default directory index template')
123  
-    files = []
124  
-    for f in os.listdir(fullpath):
125  
-        if not f.startswith('.'):
126  
-            if os.path.isdir(os.path.join(fullpath, f)):
127  
-                f += '/'
128  
-            files.append(f)
129  
-    c = Context({
130  
-        'directory' : path + '/',
131  
-        'file_list' : files,
132  
-    })
133  
-    return HttpResponse(t.render(c))
134  
-
135  
-def was_modified_since(header=None, mtime=0, size=0):
136  
-    """
137  
-    Was something modified since the user last downloaded it?
138  
-
139  
-    header
140  
-      This is the value of the If-Modified-Since header.  If this is None,
141  
-      I'll just return True.
142  
-
143  
-    mtime
144  
-      This is the modification time of the item we're talking about.
145  
-
146  
-    size
147  
-      This is the size of the item we're talking about.
148  
-    """
149  
-    try:
150  
-        if header is None:
151  
-            raise ValueError
152  
-        matches = re.match(r"^([^;]+)(; length=([0-9]+))?$", header,
153  
-                           re.IGNORECASE)
154  
-        header_date = parsedate_tz(matches.group(1))
155  
-        if header_date is None:
156  
-            raise ValueError
157  
-        header_mtime = mktime_tz(header_date)
158  
-        header_len = matches.group(3)
159  
-        if header_len and int(header_len) != size:
160  
-            raise ValueError
161  
-        if mtime > header_mtime:
162  
-            raise ValueError
163  
-    except (AttributeError, ValueError, OverflowError):
164  
-        return True
165  
-    return False
  38
+    return static.serve(request, path, document_root=document_root, **kwargs)
6  django/core/servers/basehttp.py
@@ -18,8 +18,9 @@
18 18
 from django.core.management.color import color_style
19 19
 from django.utils.http import http_date
20 20
 from django.utils._os import safe_join
  21
+from django.views import static
21 22
 
22  
-from django.contrib.staticfiles import handlers, views as static
  23
+from django.contrib.staticfiles import handlers
23 24
 
24 25
 __version__ = "0.1"
25 26
 __all__ = ['WSGIServer','WSGIRequestHandler']
@@ -677,8 +678,7 @@ def file_path(self, url):
677 678
 
678 679
     def serve(self, request):
679 680
         document_root, path = os.path.split(self.file_path(request.path))
680  
-        return static.serve(request, path,
681  
-            document_root=document_root, insecure=True)
  681
+        return static.serve(request, path, document_root=document_root)
682 682
 
683 683
     def _should_handle(self, path):
684 684
         """
121  django/views/static.py
@@ -9,7 +9,6 @@
9 9
 import re
10 10
 import stat
11 11
 import urllib
12  
-import warnings
13 12
 from email.Utils import parsedate_tz, mktime_tz
14 13
 
15 14
 from django.template import loader
@@ -17,11 +16,7 @@
17 16
 from django.template import Template, Context, TemplateDoesNotExist
18 17
 from django.utils.http import http_date
19 18
 
20  
-from django.contrib.staticfiles.views import (directory_index,
21  
-    was_modified_since, serve as staticfiles_serve)
22  
-
23  
-
24  
-def serve(request, path, document_root=None, show_indexes=False, insecure=False):
  19
+def serve(request, path, document_root=None, show_indexes=False):
25 20
     """
26 21
     Serve static files below a given point in the directory structure.
27 22
 
@@ -35,7 +30,113 @@ def serve(request, path, document_root=None, show_indexes=False, insecure=False)
35 30
     but if you'd like to override it, you can create a template called
36 31
     ``static/directory_index.html``.
37 32
     """
38  
-    warnings.warn("The view at `django.views.static.serve` is deprecated; "
39  
-                  "use the path `django.contrib.staticfiles.views.serve` "
40  
-                  "instead.", PendingDeprecationWarning)
41  
-    return staticfiles_serve(request, path, document_root, show_indexes, insecure)
  33
+    path = posixpath.normpath(urllib.unquote(path))
  34
+    path = path.lstrip('/')
  35
+    newpath = ''
  36
+    for part in path.split('/'):
  37
+        if not part:
  38
+            # Strip empty path components.
  39
+            continue
  40
+        drive, part = os.path.splitdrive(part)
  41
+        head, part = os.path.split(part)
  42
+        if part in (os.curdir, os.pardir):
  43
+            # Strip '.' and '..' in path.
  44
+            continue
  45
+        newpath = os.path.join(newpath, part).replace('\\', '/')
  46
+    if newpath and path != newpath:
  47
+        return HttpResponseRedirect(newpath)
  48
+    fullpath = os.path.join(document_root, newpath)
  49
+    if os.path.isdir(fullpath):
  50
+        if show_indexes:
  51
+            return directory_index(newpath, fullpath)
  52
+        raise Http404("Directory indexes are not allowed here.")
  53
+    if not os.path.exists(fullpath):
  54
+        raise Http404('"%s" does not exist' % fullpath)
  55
+    # Respect the If-Modified-Since header.
  56
+    statobj = os.stat(fullpath)
  57
+    mimetype, encoding = mimetypes.guess_type(fullpath)
  58
+    mimetype = mimetype or 'application/octet-stream'
  59
+    if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
  60
+                              statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):
  61
+        return HttpResponseNotModified(mimetype=mimetype)
  62
+    contents = open(fullpath, 'rb').read()
  63
+    response = HttpResponse(contents, mimetype=mimetype)
  64
+    response["Last-Modified"] = http_date(statobj[stat.ST_MTIME])
  65
+    response["Content-Length"] = len(contents)
  66
+    if encoding:
  67
+        response["Content-Encoding"] = encoding
  68
+    return response
  69
+
  70
+
  71
+DEFAULT_DIRECTORY_INDEX_TEMPLATE = """
  72
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  73
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  74
+  <head>
  75
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
  76
+    <meta http-equiv="Content-Language" content="en-us" />
  77
+    <meta name="robots" content="NONE,NOARCHIVE" />
  78
+    <title>Index of {{ directory }}</title>
  79
+  </head>
  80
+  <body>
  81
+    <h1>Index of {{ directory }}</h1>
  82
+    <ul>
  83
+      {% ifnotequal directory "/" %}
  84
+      <li><a href="../">../</a></li>
  85
+      {% endifnotequal %}
  86
+      {% for f in file_list %}
  87
+      <li><a href="{{ f|urlencode }}">{{ f }}</a></li>
  88
+      {% endfor %}
  89
+    </ul>
  90
+  </body>
  91
+</html>
  92
+"""
  93
+
  94
+def directory_index(path, fullpath):
  95
+    try:
  96
+        t = loader.select_template(['static/directory_index.html',
  97
+                'static/directory_index'])
  98
+    except TemplateDoesNotExist:
  99
+        t = Template(DEFAULT_DIRECTORY_INDEX_TEMPLATE, name='Default directory index template')
  100
+    files = []
  101
+    for f in os.listdir(fullpath):
  102
+        if not f.startswith('.'):
  103
+            if os.path.isdir(os.path.join(fullpath, f)):
  104
+                f += '/'
  105
+            files.append(f)
  106
+    c = Context({
  107
+        'directory' : path + '/',
  108
+        'file_list' : files,
  109
+    })
  110
+    return HttpResponse(t.render(c))
  111
+
  112
+def was_modified_since(header=None, mtime=0, size=0):
  113
+    """
  114
+    Was something modified since the user last downloaded it?
  115
+
  116
+    header
  117
+      This is the value of the If-Modified-Since header.  If this is None,
  118
+      I'll just return True.
  119
+
  120
+    mtime
  121
+      This is the modification time of the item we're talking about.
  122
+
  123
+    size
  124
+      This is the size of the item we're talking about.
  125
+    """
  126
+    try:
  127
+        if header is None:
  128
+            raise ValueError
  129
+        matches = re.match(r"^([^;]+)(; length=([0-9]+))?$", header,
  130
+                           re.IGNORECASE)
  131
+        header_date = parsedate_tz(matches.group(1))
  132
+        if header_date is None:
  133
+            raise ValueError
  134
+        header_mtime = mktime_tz(header_date)
  135
+        header_len = matches.group(3)
  136
+        if header_len and int(header_len) != size:
  137
+            raise ValueError
  138
+        if mtime > header_mtime:
  139
+            raise ValueError
  140
+    except (AttributeError, ValueError, OverflowError):
  141
+        return True
  142
+    return False
71  docs/howto/static-files.txt
@@ -2,8 +2,6 @@
2 2
 Managing static files
3 3
 =====================
4 4
 
5  
-.. currentmodule:: django.contrib.staticfiles
6  
-
7 5
 .. versionadded:: 1.3
8 6
 
9 7
 Django developers mostly concern themselves with the dynamic parts of web
@@ -109,10 +107,9 @@ the framework see :doc:`the staticfiles reference </ref/contrib/staticfiles>`.
109 107
    :setting:`MEDIA_URL` different from your :setting:`STATIC_ROOT` and
110 108
    :setting:`STATIC_URL`. You will need to arrange for serving of files in
111 109
    :setting:`MEDIA_ROOT` yourself; ``staticfiles`` does not deal with
112  
-   user-uploaded files at all. You can, however, use ``staticfiles``'
113  
-   :func:`~django.contrib.staticfiles.views.serve` view for serving
114  
-   :setting:`MEDIA_ROOT` in development; see
115  
-   :ref:`staticfiles-serve-other-directories`.
  110
+   user-uploaded files at all. You can, however, use
  111
+   :func:`~django.views.static.serve` view for serving :setting:`MEDIA_ROOT`
  112
+   in development; see :ref:`staticfiles-other-directories`.
116 113
 
117 114
 .. _staticfiles-in-templates:
118 115
 
@@ -241,8 +238,64 @@ files in app directories.
241 238
     :setting:`STATIC_URL` setting can't be empty or a full URL, such as
242 239
     ``http://static.example.com/``.
243 240
 
244  
-For a few more details, including an alternate method of enabling this view,
245  
-see :ref:`staticfiles-development-view`.
  241
+For a few more details on how the ``staticfiles`` can be used during
  242
+development, see :ref:`staticfiles-development-view`.
  243
+
  244
+.. _staticfiles-other-directories:
  245
+
  246
+Serving other directories
  247
+-------------------------
  248
+
  249
+.. currentmodule:: django.views.static
  250
+.. function:: serve(request, path, document_root, show_indexes=False)
  251
+
  252
+There may be files other than your project's static assets that, for
  253
+convenience, you'd like to have Django serve for you in local development.
  254
+The :func:`~django.views.static.serve` view can be used to serve any directory
  255
+you give it. (Again, this view is **not** hardened for production
  256
+use, and should be used only as a development aid; you should serve these files
  257
+in production using a real front-end webserver).
  258
+
  259
+The most likely example is user-uploaded content in :setting:`MEDIA_ROOT`.
  260
+``staticfiles`` is intended for static assets and has no built-in handling
  261
+for user-uploaded files, but you can have Django serve your
  262
+:setting:`MEDIA_ROOT` by appending something like this to your URLconf::
  263
+
  264
+    from django.conf import settings
  265
+
  266
+    # ... the rest of your URLconf goes here ...
  267
+
  268
+    if settings.DEBUG:
  269
+        urlpatterns += patterns('',
  270
+            url(r'^media/(?P<path>.*)$', 'django.views.static', {
  271
+                'document_root': settings.MEDIA_ROOT,
  272
+            }),
  273
+       )
  274
+
  275
+Note, the snippet assumes your :setting:`MEDIA_URL` has a value of
  276
+``'/media/'``. This will call the :func:`~django.views.static.serve` view,
  277
+passing in the path from the URLconf and the (required) ``document_root``
  278
+parameter.
  279
+
  280
+.. currentmodule:: django.conf.urls.static
  281
+.. function:: static(prefix, view='django.views.static.serve', **kwargs)
  282
+
  283
+Since it can become a bit cumbersome to define this URL pattern, Django
  284
+ships with a small URL helper function
  285
+:func:`~django.conf.urls.static.static` that taks as parameters the prefix
  286
+such as :setting:`MEDIA_URL` and a dotted path to a view, such as
  287
+``'django.views.static.serve'``. Any other function parameter will be
  288
+transparently passed to the view.
  289
+
  290
+An example for serving :setting:`MEDIA_URL` (``'/media/'``) during
  291
+development::
  292
+
  293
+    from django.conf import settings
  294
+    from django.conf.urls.static import static
  295
+
  296
+    urlpatterns = patterns('',
  297
+        # ... the rest of your URLconf goes here ...
  298
+    ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
246 299
 
247 300
 .. _staticfiles-production:
248 301
 
@@ -395,7 +448,7 @@ Upgrading from ``django-staticfiles``
395 448
 =====================================
396 449
 
397 450
 ``django.contrib.staticfiles`` began its life as `django-staticfiles`_. If
398  
-you're upgrading from `django-staticfiles`_ < ``1.0``` (e.g. ``0.3.4``) to
  451
+you're upgrading from `django-staticfiles`_ older than 1.0 (e.g. 0.3.4) to
399 452
 ``django.contrib.staticfiles``, you'll need to make a few changes:
400 453
 
401 454
     * Application files should now live in a ``static`` directory in each app
28  docs/ref/contrib/staticfiles.txt
@@ -317,31 +317,3 @@ already defined pattern list. Use it like this::
317 317
     This helper function will only work if :setting:`DEBUG` is ``True``
318 318
     and your :setting:`STATIC_URL` setting is neither empty nor a full
319 319
     URL such as ``http://static.example.com/``.
320  
-
321  
-.. _staticfiles-serve-other-directories:
322  
-
323  
-Serving other directories
324  
-"""""""""""""""""""""""""
325  
-
326  
-There may be files other than your project's static assets that, for
327  
-convenience, you'd like to have Django serve for you in local development. The
328  
-:func:`~django.contrib.staticfiles.views.serve` view can be used to serve any
329  
-directory you give it. (Again, this view is **not** hardened for production
330  
-use, and should be used only as a development aid; you should serve these files
331  
-in production using a real front-end webserver).
332  
-
333  
-The most likely example is user-uploaded content in :setting:`MEDIA_ROOT`.
334  
-``staticfiles`` is intended for static assets and has no built-in handling for
335  
-user-uploaded files, but you can have Django serve your :setting:`MEDIA_ROOT`
336  
-by appending something like this to your URLconf::
337  
-
338  
-   from django.conf import settings
339  
-
340  
-   if settings.DEBUG:
341  
-       urlpatterns += patterns('django.contrib.staticfiles.views',
342  
-           url(r'^media/(?P<path>.*)$', 'serve',
343  
-               {'document_root': settings.MEDIA_ROOT}),
344  
-       )
345  
-
346  
-This snippet assumes you've also set your :setting:`MEDIA_URL` (in development)
347  
-to ``/media/``.
5  tests/regressiontests/staticfiles_tests/tests.py
@@ -293,9 +293,8 @@ def setUp(self):
293 293
         settings.DEBUG = False
294 294
 
295 295
     def test_disabled_serving(self):
296  
-        self.assertRaisesRegexp(ImproperlyConfigured, 'The view to serve '
297  
-            'static files can only be used if the DEBUG setting is True',
298  
-            self._response, 'test.txt')
  296
+        self.assertRaisesRegexp(ImproperlyConfigured, 'The staticfiles view '
  297
+            'can only be used in debug mode ', self._response, 'test.txt')
299 298
 
300 299
 
301 300
 class TestServeStaticWithDefaultURL(TestServeStatic, TestDefaults):

0 notes on commit a26034f

Please sign in to comment.
Something went wrong with that request. Please try again.