Normally you should not access files using open()in a Django application. You must use the storage API. This allows your code to play well with Django settings and potential third-party applications that complement this API.
https://docs.djangoproject.com/en/1.7/topics/files/#file-storage
So here you should do something like
from django.core.files.storage import default_storage
f = default_storage.open(os.path.join('Data_Files', new_file), 'r')
data = f.read()
f.close()
print(data)
, , , , , . , MEDIA_ROOT. settings.UPLOADS_ROOT ( - MEDIA_ROOT, ).
from django.conf import settings
from django.core.files.storage import FileSystemStorage, get_storage_class
from django.utils.functional import LazyObject
class UploadsStorage(FileSystemStorage):
def __init__(self, location=None, base_url=None, *args, **kwargs):
if location is None:
location = getattr(settings, 'UPLOADS_ROOT', None)
super(UploadsStorage, self).__init__(location, base_url, *args, **kwargs)
self.base_url = None
class ConfiguredStorage(LazyObject):
def _setup(self):
storage = getattr(settings, 'UPLOADS_STORAGE', None)
klass = UploadsStorage if storage is None else get_storage_class(storage)
self._wrapped = klass()
uploads_storage = ConfiguredStorage()
. , . , .
, :
from myapp.storage import uploads_storage
f = uploads_storage.open(new_files, 'r')
UPLOADS_ROOT . , - -. - , UPLOADS_STORAGE , .