2010-10-20 09:33:24 +08:00
|
|
|
import re
|
|
|
|
from django.conf import settings
|
|
|
|
from django.conf.urls.defaults import patterns, url, include
|
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
|
|
|
|
urlpatterns = []
|
|
|
|
|
|
|
|
# only serve non-fqdn URLs
|
2010-10-21 11:16:41 +08:00
|
|
|
if settings.DEBUG:
|
2010-10-20 09:33:24 +08:00
|
|
|
urlpatterns += patterns('',
|
|
|
|
url(r'^(?P<path>.*)$', 'django.contrib.staticfiles.views.serve'),
|
|
|
|
)
|
|
|
|
|
|
|
|
def staticfiles_urlpatterns(prefix=None):
|
|
|
|
"""
|
|
|
|
Helper function to return a URL pattern for serving static files.
|
|
|
|
"""
|
2010-10-21 11:16:41 +08:00
|
|
|
if not settings.DEBUG:
|
2010-10-20 09:33:24 +08:00
|
|
|
return []
|
|
|
|
if prefix is None:
|
2010-11-17 23:36:26 +08:00
|
|
|
prefix = settings.STATIC_URL
|
|
|
|
if not prefix or '://' in prefix:
|
2010-11-12 05:43:49 +08:00
|
|
|
raise ImproperlyConfigured(
|
2010-11-17 23:36:26 +08:00
|
|
|
"The prefix for the 'staticfiles_urlpatterns' helper is invalid.")
|
2010-10-20 09:33:24 +08:00
|
|
|
if prefix.startswith("/"):
|
|
|
|
prefix = prefix[1:]
|
|
|
|
return patterns('',
|
|
|
|
url(r'^%s' % re.escape(prefix), include(urlpatterns)),)
|