Python flask.current_app.static_folder() Examples
The following are 15
code examples of flask.current_app.static_folder().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.current_app
, or try the search function
.
Example #1
Source File: html.py From beibq with BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example #2
Source File: views.py From shhh with MIT License | 5 votes |
def robots(): """Robots handler.""" return send_from_directory(app.static_folder, request.path[1:])
Example #3
Source File: static.py From udata with GNU Affero General Public License v3.0 | 5 votes |
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')
Example #4
Source File: versioned_static.py From evesrp with BSD 2-Clause "Simplified" License | 5 votes |
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
Example #5
Source File: cli.py From flask-static-digest with MIT License | 5 votes |
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"))
Example #6
Source File: cli.py From flask-static-digest with MIT License | 5 votes |
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"))
Example #7
Source File: file.py From beibq with BSD 3-Clause "New" or "Revised" License | 5 votes |
def generate_origin_avatar(name, im): """ 生成原始大小的头像 """ avatar_image = "/".join([current_app.static_folder, current_app.config["AVATAR_PATH"], name]) im.save(avatar_image)
Example #8
Source File: file.py From beibq with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #9
Source File: file.py From beibq with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #10
Source File: file.py From beibq with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #11
Source File: file.py From beibq with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #12
Source File: file.py From beibq with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #13
Source File: file.py From beibq with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #14
Source File: editor.py From knowledge-repo with Apache License 2.0 | 5 votes |
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})
Example #15
Source File: static_page.py From NaturewatchCameraServer with GNU General Public License v3.0 | 5 votes |
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)