settings.py
MEDIA_URL = '/media/'
MEDIA_ROOT = '/Users/blah/djangoproj/abc/abc/media/static/'
In random.py file, how do I access files within MEDIA_ROOT? How should I add media_root to urls.py?
you can just import it from your settings.py file
from django.conf import settings #or from my_project import settings
print settings.MEDIA_ROOT
in urls.py
from django.utils.translation import ugettext_lazy as _
from django.conf.urls.defaults import *
from django.conf import settings
urls = (...
(r'^%s(?P<path>.*)$'%settings.MEDIA_URL, 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT,
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With