本文整理汇总了Python中django.core.files.storage.DefaultStorage.path方法的典型用法代码示例。如果您正苦于以下问题:Python DefaultStorage.path方法的具体用法?Python DefaultStorage.path怎么用?Python DefaultStorage.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.core.files.storage.DefaultStorage
的用法示例。
在下文中一共展示了DefaultStorage.path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: random_image
# 需要导入模块: from django.core.files.storage import DefaultStorage [as 别名]
# 或者: from django.core.files.storage.DefaultStorage import path [as 别名]
def random_image(field):
# Delay import to avoid hard dependency
from PIL import Image, ImageDraw
color1 = random_rgb()
color2 = random_rgb()
color3 = random_rgb()
color4 = random_rgb()
size = (random.randint(300, 900), random.randint(300, 900))
im = Image.new("RGB", size) # create the image
draw = ImageDraw.Draw(im) # create a drawing object that is
draw.rectangle(
[(0, 0), ((size[0] / 2), (size[1] / 2))],
fill=color1
)
draw.rectangle(
[((size[0] / 2), 0), ((size[1] / 2), size[0])],
fill=color2
)
draw.rectangle(
[(0, (size[1] / 2)), ((size[0] / 2), size[1])],
fill=color3
)
draw.rectangle(
[((size[0] / 2), (size[1] / 2)), (size[0], size[1])],
fill=color4
)
filename = "%s.png" % uuid.uuid4().hex[:10]
filename = field.generate_filename(None, filename)
storage = DefaultStorage()
full_path = storage.path(filename)
directory = os.path.dirname(full_path)
try:
os.makedirs(directory)
except OSError as e:
if e.errno != errno.EEXIST:
raise
filehandle = storage.open(filename, mode="w")
im.save(filehandle, "PNG")
filehandle.close()
return filename # and we"re done!
示例2: random_image
# 需要导入模块: from django.core.files.storage import DefaultStorage [as 别名]
# 或者: from django.core.files.storage.DefaultStorage import path [as 别名]
def random_image(field):
color1 = random_rgb()
color2 = random_rgb()
color3 = random_rgb()
color4 = random_rgb()
size = (random.randint(300, 900), random.randint(300, 900))
im = Image.new("RGB", size) # create the image
draw = ImageDraw.Draw(im) # create a drawing object that is
draw.rectangle(
[(0, 0), ((size[0] / 2), (size[1] / 2))],
fill=color1
)
draw.rectangle(
[((size[0] / 2), 0), ((size[1] / 2), size[0])],
fill=color2
)
draw.rectangle(
[(0, (size[1] / 2)), ((size[0] / 2), size[1])],
fill=color3
)
draw.rectangle(
[((size[0] / 2), (size[1] / 2)), (size[0], size[1])],
fill=color4
)
filename = "%s.png" % uuid.uuid4().hex[:10]
filename = field.generate_filename(None, filename)
storage = DefaultStorage()
full_path = storage.path(filename)
directory = os.path.dirname(full_path)
try:
os.makedirs(directory)
except OSError, e:
if e.errno != errno.EEXIST:
raise