utils.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:website 作者: lasa 项目源码 文件源码
def get_uploads():
    """gets the images and other files from the uploads directory
    and returns two lists of tuples in the form (name, path)
    """

    images = [('none', '')]
    others = [('none', '')]

    uploads = os.listdir(os.path.join(app.root_path, app.config['UPLOAD_FOLDER']))
    uploads.remove(".gitignore")
    # sort by time last modified
    uploads.sort(key=lambda filename: os.stat(os.path.join(app.root_path, app.config['UPLOAD_FOLDER'], filename)).st_mtime)
    image_extensions = ["png", "jpg", "jpeg", "gif", "bmp"]

    for upload in uploads[::-1]:
        if '.' in upload and upload.rsplit('.', 1)[1].lower() in image_extensions:
            images.append(('/uploads/' + upload, upload))
        else:
            others.append(('/uploads/' + upload, upload))
    return images, others

# custom widget for rendering a TinyMCE input
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号