[Answer]-Django: Migrating from MEDIA_URL to STATIC_URL

1👍

settings.py

PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))

MEDIA_ROOT = os.path.join(PROJECT_DIR, 'site_media')
MEDIA_URL = '/site_media/'
STATIC_URL = '/static/'

if DEBUG:
    STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
else:
    STATICFILES_DIRS = (
        os.path.join(PROJECT_DIR, 'static'),
    )

urls.py

if settings.DEBUG:
    urlpatterns += patterns('',
        url(r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
        url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
    ) 

That should work 🙂

👤Efrin

Leave a comment