PageRenderTime 19ms CodeModel.GetById 15ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/django/conf/urls/static.py

https://code.google.com/p/mango-py/
Python | 25 lines | 14 code | 2 blank | 9 comment | 0 complexity | 011b0dfaecf77bbf29ae78021155b811 MD5 | raw file
 1import re
 2from django.conf import settings
 3from django.conf.urls.defaults import patterns, url
 4from django.core.exceptions import ImproperlyConfigured
 5
 6def 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    )