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,
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.