## urls.py

from django.conf.urls.defaults import *
from django.conf import settings

urlpatterns = patterns("",
    # ...
)

if settings.DEBUG:
    urlpatterns += patterns("",
        *tuple((u, 'django.views.static.serve',
                {'document_root': settings.MEDIA_ROOT}) for u in settings.MEDIA_URLCONF)
    )

## settings.py

# Absolute path to the directory that holds media.
MEDIA_ROOT = '/path/to/media'

# Regular expressions to match media requests for the debugging static serve.
MEDIA_URLCONF = (r'^media/(?P<path>.*)$',)