本文整理汇总了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
示例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:])
示例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')
示例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
示例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"))
示例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"))
示例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)
示例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)
示例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)
示例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
示例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)
示例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
示例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
示例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})
示例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)