Statistics
| Branch: | Revision:

root / env / lib / python2.7 / site-packages / django / conf / urls / static.py @ 1a305335

History | View | Annotate | Download (884 Bytes)

1
import re
2
from django.conf import settings
3
from django.conf.urls 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
    # No-op if not in debug mode or an non-local prefix
19
    if not settings.DEBUG or (prefix and '://' in prefix):
20
        return []
21
    elif not prefix:
22
        raise ImproperlyConfigured("Empty static prefix not permitted")
23
    return patterns('',
24
        url(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs),
25
    )