settings.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,
})
os.path.join(settings.STATIC_ROOT,settings.MEDIA_ROOT)
... 对于那个应该没问题... - Joran Beasley