本文整理汇总了Python中django.core.files.storage.DefaultStorage.listdir方法的典型用法代码示例。如果您正苦于以下问题:Python DefaultStorage.listdir方法的具体用法?Python DefaultStorage.listdir怎么用?Python DefaultStorage.listdir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.files.storage.DefaultStorage
的用法示例。
在下文中一共展示了DefaultStorage.listdir方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_dirnames
# 需要导入模块: from django.core.files.storage import DefaultStorage [as 别名]
# 或者: from django.core.files.storage.DefaultStorage import listdir [as 别名]
def get_dirnames(path):
""" Get all directory names in path as list of strings
Raises: OSError if directory can not be found
"""
storage = DefaultStorage()
dirnames = storage.listdir(path)[0]
dirnames.sort()
return dirnames
示例2: cleanup_screenshot_files
# 需要导入模块: from django.core.files.storage import DefaultStorage [as 别名]
# 或者: from django.core.files.storage.DefaultStorage import listdir [as 别名]
def cleanup_screenshot_files():
"""Remove stale screenshots"""
storage = DefaultStorage()
try:
files = storage.listdir('screenshots')[1]
except OSError:
return
for name in files:
fullname = os.path.join('screenshots', name)
if not Screenshot.objects.filter(image=fullname).exists():
storage.delete(fullname)
示例3: render
# 需要导入模块: from django.core.files.storage import DefaultStorage [as 别名]
# 或者: from django.core.files.storage.DefaultStorage import listdir [as 别名]
def render(self, context):
challenge: Challenge = context["currentpage"].challenge
try:
projectpath = safe_join(
challenge.get_project_data_folder(), self.path
)
except SuspiciousFileOperation:
return self.make_dataset_error_msg(
"path is outside the challenge folder."
)
storage = DefaultStorage()
try:
filenames = storage.listdir(projectpath)[1]
except OSError as e:
return self.make_dataset_error_msg(str(e))
filenames.sort()
# if extensionsFilter is given, show only filenames with those extensions
if "extensionFilter" in self.args.keys():
extensions = self.args["extensionFilter"].split(",")
filenames = filter_by_extension(filenames, extensions)
links = []
for filename in filenames:
downloadlink = reverse(
"root-serving:challenge-file",
kwargs={
"challenge_name": challenge.short_name,
"path": f"{self.path}/{filename}",
},
)
links.append(
'<li><a href="' + downloadlink + '">' + filename + " </a></li>"
)
htmlOut = '<ul class="dataset">' + "".join(links) + "</ul>"
return htmlOut