2011-02-14 09:42:26 +08:00
|
|
|
import re
|
|
|
|
from django.conf import settings
|
2011-09-12 06:36:16 +08:00
|
|
|
from django.conf.urls import patterns, url
|
2011-02-14 09:42:26 +08:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
|
|
|
|
def static(prefix, view='django.views.static.serve', **kwargs):
|
|
|
|
"""
|
|
|
|
Helper function to return a URL pattern for serving files in debug mode.
|
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
from django.conf.urls.static import static
|
|
|
|
|
|
|
|
urlpatterns = patterns('',
|
|
|
|
# ... the rest of your URLconf goes here ...
|
|
|
|
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
|
|
|
|
|
|
|
"""
|
2011-03-16 04:13:21 +08:00
|
|
|
# No-op if not in debug mode or an non-local prefix
|
|
|
|
if not settings.DEBUG or (prefix and '://' in prefix):
|
2011-02-14 09:42:26 +08:00
|
|
|
return []
|
|
|
|
elif not prefix:
|
|
|
|
raise ImproperlyConfigured("Empty static prefix not permitted")
|
|
|
|
return patterns('',
|
2011-02-16 20:50:57 +08:00
|
|
|
url(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs),
|
2011-02-14 09:42:26 +08:00
|
|
|
)
|