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


Python Message.image_filename方法代码示例

本文整理汇总了Python中models.Message.image_filename方法的典型用法代码示例。如果您正苦于以下问题:Python Message.image_filename方法的具体用法?Python Message.image_filename怎么用?Python Message.image_filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Message的用法示例。


在下文中一共展示了Message.image_filename方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import image_filename [as 别名]
def create():
    ''' Save new message. '''
    if not (request.POST.get('nickname') and request.POST.get('text')):
        redirect('/')
    msg = Message()
    msg.nickname = request.POST['nickname']
    msg.text = request.POST['text']
    if 'image' in request.files:
        upload = request.files['image']
        if not upload.filename.lower().endswith(
                ('.jpg', '.jpeg', '.png', '.bmp', '.gif')):
            redirect('/')
        mime = mimetypes.guess_type(upload.filename)[0]
        msg.image_filename = upload.filename
        # Save fullsize image
        msg.image.put(upload.file, content_type=mime)
        # Create and save thumbnail
        image = Image.open(msg.image)
        image.thumbnail((80, 60), Image.ANTIALIAS)
        data = StringIO.StringIO()
        image.save(data, image.format)
        data.seek(0)
        msg.thumb.put(data, content_type=mime)
    msg.save()
    redirect('/')
开发者ID:iontom,项目名称:bottle-mongodb-example,代码行数:27,代码来源:controllers.py

示例2: create

# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import image_filename [as 别名]
def create():
    """ Save new message. """
    if not (request.POST.get("nickname") and request.POST.get("text")):
        redirect("/")
    msg = Message()
    msg.nickname = request.POST["nickname"]
    msg.text = request.POST["text"]
    if "image" in request.files:
        upload = request.files["image"]
        if not upload.filename.lower().endswith((".jpg", ".jpeg", ".png", ".bmp", ".gif")):
            redirect("/")
        mime = mimetypes.guess_type(upload.filename)[0]
        msg.image_filename = upload.filename
        # Save fullsize image
        msg.image.put(upload.file, content_type=mime)
        # Create and save thumbnail
        image = Image.open(msg.image)
        image.thumbnail((80, 60), Image.ANTIALIAS)
        data = StringIO.StringIO()
        image.save(data, image.format)
        data.seek(0)
        msg.thumb.put(data, content_type=mime)
    msg.save()
    redirect("/")
开发者ID:srackham,项目名称:bottle-mongodb-example,代码行数:26,代码来源:controllers.py


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