PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause
  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. def static(prefix, view='django.views.static.serve', **kwargs):
  6. """
  7. Helper function to return a URL pattern for serving files in debug mode.
  8. from django.conf import settings
  9. from django.conf.urls.static import static
  10. urlpatterns = patterns('',
  11. # ... the rest of your URLconf goes here ...
  12. ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
  13. """
  14. # No-op if not in debug mode or an non-local prefix
  15. if not settings.DEBUG or (prefix and '://' in prefix):
  16. return []
  17. elif not prefix:
  18. raise ImproperlyConfigured("Empty static prefix not permitted")
  19. return patterns('',
  20. url(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs),
  21. )