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


Python current_app.static_folder方法代码示例

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


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

示例1: download_html_image

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def download_html_image(url, html, path):
    """ 下载html中的图片 """
    soup = BeautifulSoup(html, "html.parser")
    imgs = soup.select("img")
    for img in imgs:
        if not img.has_attr("src"):
            continue
        src = img['src'] if not url else full_url(url, img["src"])
        _, ext = os.path.splitext(src)
        filename = "/{0}/{1}{2}".format(path, uuid.uuid1().hex, ext)
        _filename = "{0}{1}".format(current_app.static_folder, filename)
        _src = "{0}{1}".format("/static", filename)
        if not download_file(src, _filename):
            img['src'] = src
        else:
            img['src'] = _src
    return soup 
开发者ID:chaijunit,项目名称:beibq,代码行数:19,代码来源:html.py

示例2: robots

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def robots():
    """Robots handler."""
    return send_from_directory(app.static_folder, request.path[1:]) 
开发者ID:smallwat3r,项目名称:shhh,代码行数:5,代码来源:views.py

示例3: collect

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def collect(path, no_input):
    '''Collect static files'''
    if exists(path):
        msg = '"%s" directory already exists and will be erased'
        log.warning(msg, path)
        if not no_input:
            click.confirm('Are you sure?', abort=True)

        log.info('Deleting static directory "%s"', path)
        shutil.rmtree(path)

    prefix = current_app.static_url_path or current_app.static_folder
    if prefix.startswith('/'):
        prefix = prefix[1:]
    destination = join(path, prefix)
    log.info('Copying application assets into "%s"', destination)
    shutil.copytree(current_app.static_folder, destination)

    for blueprint in current_app.blueprints.values():
        if blueprint.has_static_folder:
            prefix = current_app.static_prefixes.get(blueprint.name)
            prefix = prefix or blueprint.url_prefix or ''
            prefix += blueprint.static_url_path or ''
            if prefix.startswith('/'):
                prefix = prefix[1:]

            log.info('Copying %s assets to %s', blueprint.name, prefix)
            destination = join(path, prefix)
            copy_recursive(blueprint.static_folder, destination)

    for prefix, source in current_app.config['STATIC_DIRS']:
        log.info('Copying %s to %s', source, prefix)
        destination = join(path, prefix)
        copy_recursive(source, destination)

    log.info('Done') 
开发者ID:opendatateam,项目名称:udata,代码行数:38,代码来源:static.py

示例4: get_file_hash

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def get_file_hash(filename):
    if not hasattr(g, 'static_hashes'):
        g.static_hashes = {}
    # Check the cache if not in debug mode
    if not current_app.debug:
        try:
            return g.static_hashes[filename]
        except KeyError:
            pass
    hasher = hashlib.md5()
    with open(safe_join(current_app.static_folder, filename), 'rb') as f:
        hasher.update(f.read())
    filehash = hasher.hexdigest()[:8]
    g.static_hashes[filename] = filehash
    return filehash 
开发者ID:paxswill,项目名称:evesrp,代码行数:17,代码来源:versioned_static.py

示例5: compile

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def compile():
    """Generate optimized static files and a cache manifest."""
    _compile(current_app.static_folder,
             current_app.static_folder,
             current_app.config.get("FLASK_STATIC_DIGEST_BLACKLIST_FILTER"),
             current_app.config.get("FLASK_STATIC_DIGEST_GZIP_FILES")) 
开发者ID:nickjj,项目名称:flask-static-digest,代码行数:8,代码来源:cli.py

示例6: clean

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def clean():
    """Remove generated static files and cache manifest."""
    _clean(current_app.static_folder,
           current_app.config.get("FLASK_STATIC_DIGEST_BLACKLIST_FILTER"),
           current_app.config.get("FLASK_STATIC_DIGEST_GZIP_FILES")) 
开发者ID:nickjj,项目名称:flask-static-digest,代码行数:7,代码来源:cli.py

示例7: generate_origin_avatar

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def generate_origin_avatar(name, im):
    """ 生成原始大小的头像 """
    avatar_image = "/".join([current_app.static_folder,
        current_app.config["AVATAR_PATH"], name])
    im.save(avatar_image) 
开发者ID:chaijunit,项目名称:beibq,代码行数:7,代码来源:file.py

示例8: generate_50px_avatar

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def generate_50px_avatar(name, im):
    """ 生成50*50大小的头像 """
    name = "50_50_{0}".format(name)
    avatar_image = "/".join([current_app.static_folder,
        current_app.config["AVATAR_PATH"], name])
    _im = im.resize((50, 50), Image.ANTIALIAS)
    _im.save(avatar_image) 
开发者ID:chaijunit,项目名称:beibq,代码行数:9,代码来源:file.py

示例9: generate_20px_avatar

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def generate_20px_avatar(name, im):
    """ 生成20*20大小的头像 """
    name = "20_20_{0}".format(name)
    avatar_image = "/".join([current_app.static_folder,
        current_app.config["AVATAR_PATH"], name])
    _im = im.resize((20, 20), Image.ANTIALIAS)
    _im.save(avatar_image) 
开发者ID:chaijunit,项目名称:beibq,代码行数:9,代码来源:file.py

示例10: new_avatar

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def new_avatar():
    common_image = '/'.join([current_app.static_folder, 
        current_app.config["STATIC_IMG_PATH"],
        "avatar.jpg"])
    u = uuid.uuid1()
    name = '{0}.jpg'.format(u.hex)
    im = Image.open(common_image)
    generate_origin_avatar(name, im)
    generate_50px_avatar(name, im)
    generate_20px_avatar(name, im)
    return name 
开发者ID:chaijunit,项目名称:beibq,代码行数:13,代码来源:file.py

示例11: new_tmp

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def new_tmp(file):
    """ 新建临时文件 """
    u = uuid.uuid1()
    name, ext = os.path.splitext(file.filename)
    filename = ''.join([u.hex, ext])
    path = "/".join([current_app.static_folder, 
        current_app.config["TMP_PATH"], filename])
    file.save(path)
    return (filename, name) 
开发者ID:chaijunit,项目名称:beibq,代码行数:11,代码来源:file.py

示例12: enable_tmp

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def enable_tmp(path, name):
    """ 激活临时文件 """
    filename = '/'.join([current_app.static_folder, 
        current_app.config["TMP_PATH"], name])
    if not os.path.exists(filename):
        return False
    _filename = '/'.join([current_app.static_folder, path, name])
    shutil.move(filename, _filename)
    return True 
开发者ID:chaijunit,项目名称:beibq,代码行数:11,代码来源:file.py

示例13: delete_file

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def delete_file(path, name):
    """ 删除文件 """
    filename= '/'.join([current_app.static_folder,  path, name])
    if not os.path.exists(filename):
        return False
    os.remove(filename)
    return True 
开发者ID:chaijunit,项目名称:beibq,代码行数:9,代码来源:file.py

示例14: file_upload

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def file_upload():
    """ Uploads images dropped on the web editor's markdown box to static/images
        and notifies editors by email
    """
    upload_folder = 'images'
    title = request.form['title']
    files = request.files
    uploadedFiles = []

    if files:
        for img_file in files.values():
            filename = secure_filename(title + "_" + img_file.filename).lower()
            dst_folder = os.path.join(current_app.static_folder, upload_folder)

            if is_allowed_image_format(img_file):
                try:
                    img_file.save(os.path.join(dst_folder, filename))
                    send_from_directory(dst_folder, filename)
                    uploadedFiles += [url_for("static", filename=os.path.join(upload_folder, filename))]
                except Exception as e:
                    error_msg = "ERROR during image upload: {}".format(str(e))
                    logger.error(error_msg)
                    return json.dumps({'error_msg': error_msg, 'success': False})

            elif is_pdf(filename):
                from PyPDF2 import PdfFileReader
                try:
                    src_pdf = PdfFileReader(img_file)
                    filename = os.path.splitext(filename)[0]
                    num_pages = src_pdf.getNumPages()
                    for page_num in range(num_pages):
                        page_png = pdf_page_to_png(src_pdf, page_num)
                        page_name = "{filename}_{page_num}.jpg".format(**locals())
                        page_png.save(filename=os.path.join(dst_folder, page_name))
                        uploadedFiles += [url_for("static", filename=os.path.join(upload_folder, page_name))]
                except Exception as e:
                    error_msg = "ERROR during pdf upload: {}".format(str(e))
                    logger.error(error_msg)
                    return json.dumps({'error_msg': error_msg, 'success': False})

    return json.dumps({'links': uploadedFiles, 'success': True}) 
开发者ID:airbnb,项目名称:knowledge-repo,代码行数:43,代码来源:editor.py

示例15: serve

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import static_folder [as 别名]
def serve(path):
    """
    Static root endpoint
    :return: index.html or file requested
    """
    if path != "" and os.path.exists(os.path.join(current_app.static_folder, path)):
        return send_from_directory(current_app.static_folder, path)
    elif path == "" or "gallery" in path:
        return send_from_directory(current_app.static_folder, 'index.html')
    else:
        return Response("Page not found. Please check the URL!", status=404) 
开发者ID:interactionresearchstudio,项目名称:NaturewatchCameraServer,代码行数:13,代码来源:static_page.py


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