本文整理匯總了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)