Sachin
Sachin

Reputation: 3782

Django unable to server files in media directory but serving content from static directory

I have the following code in my settings.py file

MEDIA_ROOT_PATH = MEDIA_FILES = os.path.join(PROJECT_ROOT, "media")
MEDIA_ROOT = MEDIA_ROOT_PATH
MEDIA_URL = '/media/'
STATIC_ROOT_PATH = STATIC_FILES = os.path.join(PROJECT_ROOT, "static")
STATIC_ROOT = STATIC_ROOT_PATH
STATIC_URL = '/static/'

and this line in the urls.py file

urlpatterns += staticfiles_urlpatterns()

The developement server is able to serve contents from the /static/ directory but not /media/ directory how can I add that to the urls.py?

Upvotes: 0

Views: 178

Answers (1)

c4urself
c4urself

Reputation: 4287

Add the following to your url patterns:

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

Upvotes: 1

Related Questions