Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to access media_root in py file

Tags:

python

url

media

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?

like image 865
user1678031 Avatar asked Dec 27 '22 16:12

user1678031


1 Answers

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,
    })
like image 188
Joran Beasley Avatar answered Dec 31 '22 12:12

Joran Beasley