Using the next code to let serving media from Django only in development.
In addition it uses the variables -MEDIA_URL and MEDIA_ROOT- directly from
the settings file.
demo/urls.py
-----------------
# Serves media content. WARNING!! Only for development uses.
# On production use lighthttpd for media content.
if settings.DEBUG:
# Delete the first trailing slash, if any.
if settings.MEDIA_URL.startswith('/'):
media_url = settings.MEDIA_URL[1:]
else:
media_url = settings.MEDIA_URL
# Add the last trailing slash, if have not.
if not media_url.endswith('/'):
media_url = media_url + '/'
urlpatterns += patterns('',
(r'^' + media_url + '(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}
),
)
-----------------
Original issue reported on code.google.com by jonas....@googlemail.com on 25 Jun 2008 at 9:29
Original issue reported on code.google.com by
jonas....@googlemail.com
on 25 Jun 2008 at 9:29Attachments: