设置.py
MEDIA_URL = '/media/'
MEDIA_ROOT = '/Users/blah/djangoproj/abc/abc/media/static/'
在 random.py 文件中,如何访问 MEDIA_ROOT 中的文件?我应该如何将 media_root 添加到 urls.py?
你可以从你的 settings.py 文件中导入它
from django.conf import settings #or from my_project import settings
print settings.MEDIA_ROOT
在 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,
})