本文整理汇总了Python中models.Message.nickname方法的典型用法代码示例。如果您正苦于以下问题:Python Message.nickname方法的具体用法?Python Message.nickname怎么用?Python Message.nickname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Message
的用法示例。
在下文中一共展示了Message.nickname方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import nickname [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('/')
示例2: create
# 需要导入模块: from models import Message [as 别名]
# 或者: from models.Message import nickname [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("/")