本文整理汇总了Python中django.core.files.storage.default_storage方法的典型用法代码示例。如果您正苦于以下问题:Python storage.default_storage方法的具体用法?Python storage.default_storage怎么用?Python storage.default_storage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.files.storage
的用法示例。
在下文中一共展示了storage.default_storage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ready
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def ready(self):
from django.core.files.storage import default_storage
from storages.backends.s3boto3 import S3Boto3Storage
from django import forms
from .forms import S3FileInputMixin
if isinstance(default_storage, S3Boto3Storage) and \
S3FileInputMixin not in forms.ClearableFileInput.__bases__:
forms.ClearableFileInput.__bases__ = \
(S3FileInputMixin,) + forms.ClearableFileInput.__bases__
elif S3FileInputMixin in forms.ClearableFileInput.__bases__:
forms.ClearableFileInput.__bases__ = tuple(
cls for cls in forms.ClearableFileInput.__bases__
if cls is not S3FileInputMixin
)
checks.register(storage_check, checks.Tags.security, deploy=True)
示例2: __init__
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **kwargs):
self._primary_key_set_explicitly = 'primary_key' in kwargs
self._unique_set_explicitly = 'unique' in kwargs
self.storage = storage or default_storage
self.upload_to = upload_to
if callable(upload_to):
self.generate_filename = upload_to
kwargs['max_length'] = kwargs.get('max_length', 100)
super(FileField, self).__init__(verbose_name, name, **kwargs)
示例3: deconstruct
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def deconstruct(self):
name, path, args, kwargs = super(FileField, self).deconstruct()
if kwargs.get("max_length", None) == 100:
del kwargs["max_length"]
kwargs['upload_to'] = self.upload_to
if self.storage is not default_storage:
kwargs['storage'] = self.storage
return name, path, args, kwargs
示例4: __init__
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **kwargs):
self._primary_key_set_explicitly = 'primary_key' in kwargs
self.storage = storage or default_storage
self.upload_to = upload_to
kwargs['max_length'] = kwargs.get('max_length', 100)
super().__init__(verbose_name, name, **kwargs)
示例5: deconstruct
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def deconstruct(self):
name, path, args, kwargs = super().deconstruct()
if kwargs.get("max_length") == 100:
del kwargs["max_length"]
kwargs['upload_to'] = self.upload_to
if self.storage is not default_storage:
kwargs['storage'] = self.storage
return name, path, args, kwargs
示例6: is_in_bucket
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def is_in_bucket(object_key):
if not hasattr(default_storage, 'bucket'):
return False
else:
try:
default_storage.bucket.Object(object_key).load()
return True
except S3_ClientError as e:
if e.response['Error']['Code'] == "404":
return False
else:
raise e
示例7: handle_upload
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def handle_upload(self, request):
"""Handle file uploads from WYSIWYG."""
if request.method != 'POST':
raise Http404
if request.is_ajax():
try:
filename = request.GET['quillUploadFile']
data = request
is_raw = True
except KeyError:
return HttpResponseBadRequest("Invalid file upload.")
else:
if len(request.FILES) != 1:
return HttpResponseBadRequest("Can only upload 1 file at a time.")
try:
data = request.FILES['quillUploadFile']
filename = data.name
is_raw = False
except KeyError:
return HttpResponseBadRequest('Missing image `quillUploadFile`.')
url = save_file(data, filename, is_raw, default_storage)
response_data = {}
response_data['url'] = url
# Response content type needs to be text/html here or else
# IE will try to download the file.
return HttpResponse(json.dumps(response_data), content_type="text/html; charset=utf-8")
示例8: __init__
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def __init__(
self, verbose_name=None, name=None, upload_to="", storage=None, **kwargs
):
self.storage = storage or default_storage
self.upload_to = upload_to
super().__init__(verbose_name, name, **kwargs)
示例9: deconstruct
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def deconstruct(self):
name, path, args, kwargs = super().deconstruct()
kwargs["upload_to"] = self.upload_to
if self.storage is not default_storage:
kwargs["storage"] = self.storage
return name, path, args, kwargs
示例10: __init__
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **kwargs):
self._primary_key_set_explicitly = 'primary_key' in kwargs
self.storage = storage or default_storage
self.upload_to = upload_to
kwargs.setdefault('max_length', 100)
super().__init__(verbose_name, name, **kwargs)
示例11: __init__
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **kwargs):
self._primary_key_set_explicitly = 'primary_key' in kwargs
self.storage = storage or default_storage
self.upload_to = upload_to
kwargs['max_length'] = kwargs.get('max_length', 100)
super(FileField, self).__init__(verbose_name, name, **kwargs)
示例12: deconstruct
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def deconstruct(self):
name, path, args, kwargs = super(FileField, self).deconstruct()
if kwargs.get("max_length") == 100:
del kwargs["max_length"]
kwargs['upload_to'] = self.upload_to
if self.storage is not default_storage:
kwargs['storage'] = self.storage
return name, path, args, kwargs
示例13: storage_check
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def storage_check(app_configs, **kwargs):
if isinstance(default_storage, FileSystemStorage):
return [
Error(
'FileSystemStorage should not be used in a production environment.',
hint='Please verify your DEFAULT_FILE_STORAGE setting.',
id='s3file.E001',
)
]
return []
示例14: get_storage
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def get_storage():
''' return configured Storage '''
return default_storage # for default filesystem, (location=settings.MEDIA_ROOT)
示例15: __init__
# 需要导入模块: from django.core.files import storage [as 别名]
# 或者: from django.core.files.storage import default_storage [as 别名]
def __init__(self, verbose_name=None, name=None, upload_to='', storage=None, **kwargs):
self._primary_key_set_explicitly = 'primary_key' in kwargs
self._unique_set_explicitly = 'unique' in kwargs
self.storage = storage or default_storage
self.upload_to = upload_to
kwargs['max_length'] = kwargs.get('max_length', 100)
super(FileField, self).__init__(verbose_name, name, **kwargs)