本文整理匯總了Python中django.conf.settings.DEFAULT_FILE_STORAGE屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.DEFAULT_FILE_STORAGE屬性的具體用法?Python settings.DEFAULT_FILE_STORAGE怎麽用?Python settings.DEFAULT_FILE_STORAGE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.DEFAULT_FILE_STORAGE屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_storage_class
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DEFAULT_FILE_STORAGE [as 別名]
def get_storage_class(import_path=None):
if import_path is None:
import_path = settings.DEFAULT_FILE_STORAGE
try:
dot = import_path.rindex('.')
except ValueError:
raise ImproperlyConfigured("%s isn't a storage module." % import_path)
module, classname = import_path[:dot], import_path[dot+1:]
try:
mod = import_module(module)
except ImportError as e:
raise ImproperlyConfigured('Error importing storage module %s: "%s"' % (module, e))
try:
return getattr(mod, classname)
except AttributeError:
raise ImproperlyConfigured('Storage module "%s" does not define a "%s" class.' % (module, classname))
示例2: test__store_external_image__local_filesystem
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DEFAULT_FILE_STORAGE [as 別名]
def test__store_external_image__local_filesystem(self, mock_requests_get):
# This test is written assuming local file storage, even though
# everything apart from CI will be using S3 as its backend. The function
# HAS been tested with S3, though.
assert (
settings.DEFAULT_FILE_STORAGE
== "django.core.files.storage.FileSystemStorage"
)
mock_response = mock.Mock()
mock_response.content = image_one_bytearray
mock_requests_get.return_value = mock_response
saved_image = _store_external_image(image_url="https://example.com/test.png")
mock_requests_get.assert_called_once_with("https://example.com/test.png")
saved_image.file.open()
saved_image.file.seek(0)
comparison_content = saved_image.file.read()
self.assertEqual(bytearray(comparison_content), image_one_bytearray)
示例3: setup_test_environment
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DEFAULT_FILE_STORAGE [as 別名]
def setup_test_environment(self):
"""
Setups the environment. Creates a temporary directory
and saves default the values of environment settings
"""
super().setup_test_environment()
# save original settings
settings._original_media_root = settings.MEDIA_ROOT
settings._original_file_storage = settings.DEFAULT_FILE_STORAGE
# create a temporary directory
self._temp_media = tempfile.mkdtemp()
# set a new media directory setting
settings.MEDIA_ROOT = self._temp_media
# set a file system storage setting
storage = 'django.core.files.storage.FileSystemStorage'
settings.DEFAULT_FILE_STORAGE = storage
示例4: get_storage_class
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DEFAULT_FILE_STORAGE [as 別名]
def get_storage_class(import_path=None):
return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
示例5: get
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DEFAULT_FILE_STORAGE [as 別名]
def get(self, request):
server_version = ""
server_config = dict()
try:
with open('VERSION', 'r') as ver:
server_version = ver.read().strip()
except FileNotFoundError:
server_version = ""
server_config['DEBUG'] = settings.DEBUG
server_config['LANGUAGE_CODE'] = settings.LANGUAGE_CODE
server_config['TIME_ZONE'] = settings.TIME_ZONE
# Backends
server_config['WSGI_APPLICATION'] = settings.WSGI_APPLICATION
server_config['DEFAULT_FILE_STORAGE'] = settings.DEFAULT_FILE_STORAGE
server_config['DB_ENGINE'] = settings.DB_ENGINE
# Storage
server_config['STORAGE_TYPE'] = settings.STORAGE_TYPE
server_config['MEDIA_ROOT'] = settings.MEDIA_ROOT
server_config['AWS_STORAGE_BUCKET_NAME'] = settings.AWS_STORAGE_BUCKET_NAME
server_config['AWS_LOCATION'] = settings.AWS_LOCATION
server_config['AWS_SHARED_BUCKET'] = settings.AWS_SHARED_BUCKET
server_config['AWS_QUERYSTRING_EXPIRE'] = settings.AWS_QUERYSTRING_EXPIRE
server_config['AWS_QUERYSTRING_AUTH'] = settings.AWS_QUERYSTRING_AUTH
# Token Conf
server_config['ROTATE_REFRESH_TOKEN'] = settings.SIMPLE_JWT['ROTATE_REFRESH_TOKENS']
server_config['ACCESS_TOKEN_LIFETIME'] = settings.SIMPLE_JWT['ACCESS_TOKEN_LIFETIME']
server_config['REFRESH_TOKEN_LIFETIME'] = settings.SIMPLE_JWT['REFRESH_TOKEN_LIFETIME']
return Response({
'version': server_version,
'config': server_config
})
示例6: log_worker_monitor
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DEFAULT_FILE_STORAGE [as 別名]
def log_worker_monitor(sender, **k):
logger.info('DEBUG: {}'.format(settings.DEBUG))
logger.info('DB_ENGINE: {}'.format(settings.DB_ENGINE))
logger.info('STORAGE_TYPE: {}'.format(settings.STORAGE_TYPE))
logger.info('DEFAULT_FILE_STORAGE: {}'.format(settings.DEFAULT_FILE_STORAGE))
logger.info('MEDIA_ROOT: {}'.format(settings.MEDIA_ROOT))
logger.info('AWS_STORAGE_BUCKET_NAME: {}'.format(settings.AWS_STORAGE_BUCKET_NAME))
logger.info('AWS_LOCATION: {}'.format(settings.AWS_LOCATION))
logger.info('AWS_S3_REGION_NAME: {}'.format(settings.AWS_S3_REGION_NAME))
logger.info('AWS_QUERYSTRING_AUTH: {}'.format(settings.AWS_QUERYSTRING_AUTH))
logger.info('AWS_QUERYSTRING_EXPIRE: {}'.format(settings.AWS_QUERYSTRING_EXPIRE))
logger.info('AWS_SHARED_BUCKET: {}'.format(settings.AWS_SHARED_BUCKET))
logger.info('AWS_IS_GZIPPED: {}'.format(settings.AWS_IS_GZIPPED))
示例7: teardown_test_environment
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import DEFAULT_FILE_STORAGE [as 別名]
def teardown_test_environment(self):
"""
Deletes all temporary files and the temporary directory.
Restores original settings.
"""
super().teardown_test_environment()
# remove all temporary files
shutil.rmtree(self._temp_media, ignore_errors=True)
# restore original settings and delete saved values
settings.MEDIA_ROOT = settings._original_media_root
del settings._original_media_root
settings.DEFAULT_FILE_STORAGE = settings._original_file_storage
del settings._original_file_storage