mousadialo / django-profile

Automatically exported from code.google.com/p/django-profile
BSD 2-Clause "Simplified" License
2 stars 0 forks source link

Serving media from Django only in development #18

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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

Attachments:

GoogleCodeExporter commented 8 years ago
Added to the repository. Thanks.

Original comment by david.ru...@gmail.com on 1 Jul 2008 at 7:58

GoogleCodeExporter commented 8 years ago

Original comment by david.ru...@gmail.com on 1 Jul 2008 at 8:00