Python flask.send_from_directory() Examples
The following are 30
code examples of flask.send_from_directory().
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
, or try the search function
.
Example #1
Source File: password-pwncheck.py From password_pwncheck with MIT License | 7 votes |
def StaticRequests(): reqfile = request.path[1:] sp = os.path.join(app.root_path,cfg.staticdir) mimetype=None if reqfile == 'image.svg': mimetype = 'image/svg+xml' return send_from_directory(sp,reqfile,mimetype=mimetype)
Example #2
Source File: app.py From matplotlib-style-gallery with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _add_url_rules(self, app): @app.route('/static/css/<path:filename>') def route_css_files(filename): directory = pth.join(disk.root_dir, 'static/css') return flask.send_from_directory(directory, filename) @app.route('/build/<path:filename>') def route_build_files(filename): directory = pth.join(disk.root_dir, 'build') return flask.send_from_directory(directory, filename) @app.route('/') def render(): return self.render() @app.route('/', methods=['POST']) def update_styles(): stylesheet = request.form['input-stylesheet'] self._input_status = save_scratch_plots(stylesheet) self._input_stylesheet = stylesheet return self.render()
Example #3
Source File: helper.py From calibre-web with GNU General Public License v3.0 | 6 votes |
def do_download_file(book, book_format, client, data, headers): if config.config_use_google_drive: startTime = time.time() df = gd.getFileFromEbooksFolder(book.path, data.name + "." + book_format) log.debug('%s', time.time() - startTime) if df: return gd.do_gdrive_download(df, headers) else: abort(404) else: filename = os.path.join(config.config_calibre_dir, book.path) if not os.path.isfile(os.path.join(filename, data.name + "." + book_format)): # ToDo: improve error handling log.error('File not found: %s', os.path.join(filename, data.name + "." + book_format)) if client == "kobo" and book_format == "kepub": headers["Content-Disposition"] = headers["Content-Disposition"].replace(".kepub", ".kepub.epub") response = make_response(send_from_directory(filename, data.name + "." + book_format)) # ToDo Check headers parameter for element in headers: response.headers[element[0]] = element[1] return response ##################################
Example #4
Source File: webapp.py From ara-archive with GNU General Public License v3.0 | 6 votes |
def configure_static_route(app): # Note (dmsimard) # /static/ is provided from in-tree bundled files and libraries. # /static/packaged/ is routed to serve packaged (i.e, XStatic) libraries. # # The reason why this isn't defined as a proper view by itself is due to # a limitation in flask-frozen. Blueprint'd views methods are like so: # "<view>.<method>. The URL generator of flask-frozen is a method decorator # that expects the method name as the function and, obviously, you can't # really have dots in functions. # By having the route configured at the root of the application, there's no # dots and we can decorate "serve_static_packaged" instead of, say, # "static.serve_packaged". @app.route('/static/packaged/<module>/<path:filename>') def serve_static_packaged(module, filename): xstatic = current_app.config['XSTATIC'] if module in xstatic: return send_from_directory(xstatic[module], filename) else: abort(404)
Example #5
Source File: webserver_sub.py From qutebrowser with GNU General Public License v3.0 | 6 votes |
def send_data(path): """Send a given data file to qutebrowser. If a directory is requested, its index.html is sent. """ if hasattr(sys, 'frozen'): basedir = os.path.realpath(os.path.dirname(sys.executable)) data_dir = os.path.join(basedir, 'end2end', 'data') else: basedir = os.path.join(os.path.realpath(os.path.dirname(__file__)), '..') data_dir = os.path.join(basedir, 'data') print(basedir) if os.path.isdir(os.path.join(data_dir, path)): path += '/index.html' return flask.send_from_directory(data_dir, path)
Example #6
Source File: srv.py From rate.sx with MIT License | 6 votes |
def send_static(path): return send_from_directory(STATIC, path)
Example #7
Source File: dash-datatable-multiple-css-selectors.py From dash-recipes with MIT License | 5 votes |
def static_file(path): static_folder = os.path.join(os.getcwd(), 'static') return send_from_directory(static_folder, path)
Example #8
Source File: mapAuthoring.py From AMS with Apache License 2.0 | 5 votes |
def root(): return send_from_directory( directory="./", filename="mapViewer.html") """ return send_from_directory( directory="./", filename="map3DViewer.html") return send_from_directory( directory="./", filename="mapVRViewer.html") """
Example #9
Source File: dash_display_images.py From dash-recipes with MIT License | 5 votes |
def serve_image(image_path): image_name = '{}.png'.format(image_path) if image_name not in list_of_images: raise Exception('"{}" is excluded from the allowed static files'.format(image_path)) return flask.send_from_directory(image_directory, image_name)
Example #10
Source File: dash-datatable-custom-css.py From dash-recipes with MIT License | 5 votes |
def static_file(path): static_folder = os.path.join(os.getcwd(), 'static') return send_from_directory(static_folder, path)
Example #11
Source File: app.py From dash-recipes with MIT License | 5 votes |
def static_file(path): static_folder = os.path.join(os.getcwd(), 'static') return send_from_directory(static_folder, path)
Example #12
Source File: dash-display-error-messages.py From dash-recipes with MIT License | 5 votes |
def serve_script(filename): print(('serving {}'.format(filename))) if filename not in ['dash-error-message-display']: raise Exception('"{}" is excluded from the allowed static files'.format(filename)) return flask.send_from_directory(os.getcwd(), '{}.js'.format(filename))
Example #13
Source File: app.py From deep-landmark with BSD 3-Clause "New" or "Revised" License | 5 votes |
def serve_media(path): """ Serve Media File, **this function is only used for Debug** """ from flask import send_from_directory return send_from_directory(join(app.config['MEDIA_ROOT'], 'result'), path, \ as_attachment=True)
Example #14
Source File: experiment_server.py From Dallinger with MIT License | 5 votes |
def static_favicon(): return send_from_directory("static", "favicon.ico", mimetype="image/x-icon")
Example #15
Source File: premiumizer.py From premiumizer with MIT License | 5 votes |
def favicon(): return send_from_directory(os.path.join(app.root_path, 'static', 'img'), 'favicon.ico')
Example #16
Source File: app.py From VQA-Keras-Visual-Question-Answering with MIT License | 5 votes |
def serve_img(path): return send_from_directory('static/images/train2014/', path)
Example #17
Source File: app.py From flyingcloud with Apache License 2.0 | 5 votes |
def send_web(path): return send_from_directory('static', path)
Example #18
Source File: experiment_server.py From Dallinger with MIT License | 5 votes |
def static_robots_txt(): """Serve robots.txt from static file.""" return send_from_directory("static", "robots.txt")
Example #19
Source File: dash-download-file-link-server.py From dash-recipes with MIT License | 5 votes |
def serve_static(path): root_dir = os.getcwd() return flask.send_from_directory( os.path.join(root_dir, 'downloads'), path )
Example #20
Source File: dash-local-css-meta.py From dash-recipes with MIT License | 5 votes |
def static_file(path): static_folder = os.path.join(os.getcwd(), 'static') return send_from_directory(static_folder, path)
Example #21
Source File: dash_css.py From dash-recipes with MIT License | 5 votes |
def serve_stylesheet(): return flask.send_from_directory(os.getcwd(), stylesheet)
Example #22
Source File: server.py From web-rpi-fm with MIT License | 5 votes |
def send_static(path): if not os.path.isfile("static/" + path): return app.send_static_file('index.html') return send_from_directory('static', path)
Example #23
Source File: views.py From ACE with Apache License 2.0 | 5 votes |
def download(): enable_cached_db_connections() sha256 = request.args.get('s', None) if not sha256: return "Invalid request.", 400 if not re.match(r'^[a-fA-F0-9]{64}$', sha256): return "Invalid request.", 400 path = os.path.join(saq.SAQ_HOME, saq.CONFIG['cloudphish']['cache_dir'], sha256[0:2].lower(), sha256.lower()) if not os.path.exists(path): # if we don't have the content see if it's on another node with get_db_connection('cloudphish') as db: c = db.cursor() c.execute("""SELECT location FROM content_metadata WHERE sha256_content = UNHEX(%s)""", (sha256,)) row = c.fetchone() if row: content_location = row[0] # is this a different node? if content_location != saq.CONFIG['engine_cloudphish']['location']: return redirect('https://{}/cloudphish/download?s={}'.format(content_location, sha256)) # otherwise we just don't know about it return "Unknown content", 404 return send_from_directory(os.path.dirname(path), os.path.basename(path), as_attachment=True)
Example #24
Source File: __init__.py From ACE with Apache License 2.0 | 5 votes |
def get_file(uuid, file_uuid_or_name): storage_dir = storage_dir_from_uuid(uuid) if saq.CONFIG['engine']['work_dir'] and not os.path.isdir(storage_dir): storage_dir = workload_storage_dir(uuid) root = RootAnalysis(storage_dir=storage_dir) root.load() # is this a UUID? try: validate_uuid(file_uuid_or_name) file_observable = root.get_observable(file_uuid_or_name) if file_observable is None: abort(Response("invalid file_uuid {}".format(file_uuid_or_name), 400)) except ValueError: file_observable = root.find_observable(lambda o: o.type == F_FILE and o.value == file_uuid_or_name) if file_observable is None: abort(Response("invalid file name {}".format(file_uuid_or_name), 400)) # NOTE we use an absolute path here because if we don't then # send_from_directory makes it relavive from the app root path # which is (/opt/ace/api) target_path = os.path.join(saq.SAQ_HOME, root.storage_dir, file_observable.value) if not os.path.exists(target_path): abort(Response("file path {} does not exist".format(target_path), 400)) # XXX revisit how we save (name) files return send_from_directory(os.path.dirname(target_path), os.path.basename(target_path), as_attachment=True, attachment_filename=os.path.basename(target_path).encode().decode('latin-1', errors='ignore'))
Example #25
Source File: collector.py From cluster-insight with Apache License 2.0 | 5 votes |
def home(): """Returns the response of the '/' endpoint. Returns: The home page of the Cluster-Insight data collector. """ return flask.send_from_directory('static', 'home.html')
Example #26
Source File: app.py From pureelk with Apache License 2.0 | 5 votes |
def img(filename): return send_from_directory(os.path.join(app.static_folder, 'img'), filename)
Example #27
Source File: app.py From pureelk with Apache License 2.0 | 5 votes |
def js(filename): return send_from_directory(os.path.join(app.static_folder, 'js'), filename)
Example #28
Source File: app.py From pureelk with Apache License 2.0 | 5 votes |
def fonts(filename): return send_from_directory(os.path.join(app.static_folder, 'fonts'), filename)
Example #29
Source File: app.py From pureelk with Apache License 2.0 | 5 votes |
def css(filename): return send_from_directory(os.path.join(app.static_folder, 'css'), filename)
Example #30
Source File: logsapi.py From minemeld-core with Apache License 2.0 | 5 votes |
def get_minemeld_engine_log(): log_directory = config.get('MINEMELD_LOG_DIRECTORY_PATH', None) if log_directory is None: return jsonify(error={'message': 'LOG_DIRECTORY not set'}), 500 return send_from_directory(log_directory, 'minemeld-engine.log', as_attachment=True)