当前位置: 首页>>代码示例>>Python>>正文


Python DefaultStorage.path方法代码示例

本文整理汇总了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!
开发者ID:rpatterson,项目名称:milkman,代码行数:49,代码来源:generators.py

示例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
开发者ID:paltman,项目名称:milkman,代码行数:40,代码来源:generators.py


注:本文中的django.core.files.storage.DefaultStorage.path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。