flask.send_from_directory

Here are the examples of the python api flask.send_from_directory taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

190 Examples 7

Example 1

Project: quokka
Source File: views.py
View license
@roles_accepted('admin', 'developer')
def theme_template_files(identifier, filename):
    template_path = os.path.join(
        current_app.root_path,
        "themes",
        identifier,
        "templates"
    )
    return send_from_directory(template_path, filename)

Example 2

Project: puzzle
Source File: views.py
View license
@blueprint.route('/resources/<resource_id>')
def resource(resource_id):
    """Show a resource."""
    resource_obj = app.db.resource(resource_id)

    if 'raw' in request.args:
        return send_from_directory(os.path.dirname(resource_obj.path),
                                   os.path.basename(resource_obj.path))

    return render_template('resource.html', resource=resource_obj)

Example 3

Project: chefdash
Source File: __init__.py
View license
@app.route('/favicon.ico')
def favicon():
	return flask.send_from_directory(
		os.path.join(app.root_path, 'static'),
		'favicon.ico',
		mimetype = 'image/vnd.microsoft.icon',
	)

Example 4

Project: flask-uploads
Source File: uploads.py
View license
@uploads_mod.route('/<setname>/<path:filename>')
def uploaded_file(setname, filename):
    config = current_app.upload_set_config.get(setname)
    if config is None:
        abort(404)
    return send_from_directory(config.destination, filename)

Example 5

Project: fava
Source File: application.py
View license
@app.route('/<bfile>/document/', methods=['GET'])
def document():
    document_path = request.args.get('file_path', None)
    if document_path and g.api.is_valid_document(document_path):
        # metadata-statement-paths may be relative to the beancount-file
        if not os.path.isabs(document_path):
            document_path = os.path.join(os.path.dirname(
                os.path.realpath(g.api.beancount_file_path)), document_path)

        directory = os.path.dirname(document_path)
        filename = os.path.basename(document_path)
        return send_from_directory(directory, filename)
    else:
        return "File \"{}\" not found in entries.".format(document_path), 404

Example 6

Project: nbdiff
Source File: ResourceRequestCommand.py
View license
    def process(self, request, filename, db_session):
        return send_from_directory(
            os.path.abspath(
                os.path.join(os.path.dirname(__file__), "..")
            ) + '/static',
            filename
        )

Example 7

Project: qutebrowser
Source File: webserver_sub.py
View license
@app.route('/data/<path:path>')
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 = path + '/index.html'
    return flask.send_from_directory(data_dir, path)

Example 8

Project: p2ptracker
Source File: torrents.py
View license
@torrents.route('/', methods=['GET'])
@torrents.route('/<filename>.<ext>', methods=['GET'])
def get(filename=None, ext=None):
    if not filename and not ext:
        return jsonify(get_all_torrents())
    torrentfile = "%s.%s" % (filename, ext)
    if torrentfile not in get_all_torrents():
        return abort(404, 'torrentfile not found')
    return send_from_directory(current_app.config['UPLOAD_PATH'],
                               torrentfile, as_attachment=True)

Example 9

Project: bepasty-server
Source File: xstatic.py
View license
@blueprint.route('/xstatic/<name>', defaults=dict(filename=''))
@blueprint.route('/xstatic/<name>/<path:filename>')
def xstatic(name, filename):
    """Route to serve the xstatic files (from serve_files)"""
    try:
        base_path = serve_files[name]
    except KeyError:
        raise NotFound()

    if not filename:
        raise NotFound()

    return send_from_directory(base_path, filename)

Example 10

Project: flask-bluebone
Source File: app.py
View license
def configure_app_handlers(app):
    @app.route('/')
    def get():
        abort(404)

    @app.route('/i-used-to-be-here/')
    def iusedtobehere():
        abort(410)

    @app.route('/robots.txt')
    def static_from_root():
        return send_from_directory(app.static_folder, request.path[1:])

    @app.route('/sitemap.xml')
    def sitemap():
        url_root = request.url_root[:-1]
        rules = app.url_map.iter_rules()
        return render_template('sitemap.xml', url_root=url_root, rules=rules)

Example 11

Project: zitkino.cz
Source File: views.py
View license
@app.route('/favicon.ico')
@app.route('/apple-touch-icon.png')
@app.route('/robots.txt')
@app.route('/humans.txt')
def static_files():
    static_dir = os.path.join(app.root_path, 'static')
    return send_from_directory(static_dir, request.path.lstrip('/'))

Example 12

Project: chili
Source File: chili.py
View license
@app.route(IMAGE_LINK_PATTERN % '<path:filename>')
def image(filename):
    if not LOCAL_DEV:
        r = request.referrer.split('/')[2]
        if r != DOMAIN and r != DOMAIN2:
            abort(403)
    return send_from_directory(LOCAL_IMAGE_DIR, filename)

Example 13

Project: Prism
Source File: views.py
View license
@flask_app.route("/static/plugin/<plugin_id>/<path:static_file>")
def plugin_static(plugin_id, static_file):
	""" Allows plugins to load files from their own static directories """
	plugin = prism.get_plugin(plugin_id)
	if plugin is None:
		return 'Unknown plugin: %s' % plugin_id
	return flask.send_from_directory(plugin.static_folder, static_file)

Example 14

Project: whiskyton
Source File: files.py
View license
@files.route('/static/fonts/glyphicons-halflings-regular.<extension>')
def bootstrap_fonts(extension=None):
    basedir = app.config['BASEDIR']
    path = basedir.child('whiskyton', 'bower', 'bootstrap', 'dist', 'fonts')
    filename = 'glyphicons-halflings-regular.{}'.format(extension)
    if path.child(filename).exists():
        return send_from_directory(path, filename)
    else:
        abort(404)

Example 15

Project: whiskyton
Source File: files.py
View license
@files.route('/robots.txt')
def robots():
    basedir = app.config['BASEDIR']
    return send_from_directory(
        basedir.child('whiskyton', 'static'),
        'robots.txt'
    )

Example 16

Project: whiskyton
Source File: files.py
View license
@files.route('/favicon.ico')
def favicon():
    basedir = app.config['BASEDIR']
    return send_from_directory(
        basedir.child('whiskyton', 'static'),
        'favicon.ico'
    )

Example 17

Project: browsepy
Source File: file.py
View license
    def download(self):
        if self.is_directory:
            stream = TarFileStream(
                self.path,
                self.app.config["directory_tar_buffsize"]
                )
            return Response(stream, mimetype="application/octet-stream")
        directory, name = os.path.split(self.path)
        return send_from_directory(directory, name, as_attachment=True)

Example 18

Project: browsepy
Source File: __init__.py
View license
@app.route('/open/<path:path>', endpoint="open")
def open_file(path):
    try:
        file = File.from_urlpath(path)
        if file.is_file:
            return send_from_directory(file.parent.path, file.name)
    except OutsideDirectoryBase:
        pass
    return NotFound()

Example 19

Project: Flexget
Source File: __init__.py
View license
@webui_app.route('/<path:path>')
def serve_app(path):
    if debug:
        if path.startswith('bower_components'):
            return send_from_directory(bower_components, path.lstrip('bower_components').lstrip('/'))

        if os.path.exists(os.path.join(ui_src, path)):
            return send_from_directory(ui_src, path)

    return send_from_directory(app_base, path)

Example 20

Project: Flexget
Source File: __init__.py
View license
@webui_app.route('/')
def root():
    if not app_base:
        return send_from_directory(ui_base, 'load.failure.html')

    return send_from_directory(app_base, 'app.html')

Example 21

View license
@app.route('/serve_static/<path:filename>')
def serve_static(filename):
    """
    Sends static file
    Note - This is not the most efficient method but since only development
    system will be using it, it's OK.
    Static files in production are stored on AWS so this won't be used
    """
    return send_from_directory(os.path.realpath('.') + '/static/', filename)

Example 22

View license
def init_app(app, **kwargs):
    # pylint: disable=unused-argument
    """
    API extension initialization point.
    """
    if app.debug:
        @app.route('/swaggerui/<path:path>')
        def send_swaggerui_assets(path):
            # pylint: disable=unused-variable
            from flask import send_from_directory
            return send_from_directory('../static/', path)

    # Prevent config variable modification with runtime changes
    api_v1.authorizations = deepcopy(app.config['AUTHORIZATIONS'])

Example 23

Project: dropboxwindow
Source File: main.py
View license
@window.route('/robots.txt')
@window.route('/humans.txt')
@window.route('/qrcode.ttf')
@window.route('/manifest.webapp')
def serve_static_content():
    return send_from_directory(window.static_folder, request.path[1:])

Example 24

Project: coil
Source File: web.py
View license
@app.route('/bower_components/<path:path>')
def serve_bower_components(path):
    """Serve bower components.

    This is meant to be used ONLY by the internal dev server.
    Please configure your web server to handle requests to this URL::

        /bower_components/ => coil/data/bower_components
    """
    res = pkg_resources.resource_filename(
        'coil', os.path.join('data', 'bower_components'))
    return send_from_directory(res, path)

Example 25

Project: coil
Source File: web.py
View license
@app.route('/coil_assets/<path:path>')
def serve_coil_assets(path):
    """Serve Coil assets.

    This is meant to be used ONLY by the internal dev server.
    Please configure your web server to handle requests to this URL::

        /coil_assets/ => coil/data/coil_assets
    """
    res = pkg_resources.resource_filename(
        'coil', os.path.join('data', 'coil_assets'))
    return send_from_directory(res, path)

Example 26

Project: coil
Source File: web.py
View license
@app.route('/assets/<path:path>')
def serve_assets(path):
    """Serve Nikola assets.

    This is meant to be used ONLY by the internal dev server.
    Please configure your web server to handle requests to this URL::

        /assets/ => output/assets
    """
    res = os.path.join(app.config['NIKOLA_ROOT'],
                       _site.config["OUTPUT_FOLDER"], 'assets')
    return send_from_directory(res, path)

Example 27

Project: cluster-insight
Source File: collector.py
View license
@app.route('/', methods=['GET'])
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 28

Project: ctfscoreboard
Source File: file.py
View license
def send(attachment):
    """Send the attachment to the client."""
    return flask.send_from_directory(
        attachment_dir(), attachment.aid,
        mimetype=attachment.content_type,
        attachment_filename=attachment.filename,
        as_attachment=True)

Example 29

Project: flask-reveal
Source File: reveal.py
View license
@reveal_blueprint.route('/img/<path:filename>')
def get_img(filename):
    """
    View to render the image file on the slide

    :param filename: the image filename from the request
    :return: the image resource
    """

    return send_from_directory(current_app.config.get('MEDIA_ROOT'), filename)

Example 30

Project: indico
Source File: errors.py
View license
    def process(self, params):
        config = Config.getInstance()

        target_dir = os.path.join(
            config.getSharedTempDir(), 'reports',
            secure_filename(request.view_args['report_id']))

        return send_from_directory(
            target_dir, request.view_args['filename'],
            mimetype='text/plain', as_attachment=True)

Example 31

Project: indico
Source File: app.py
View license
def handle_404(exception):
    try:
        if re.search(r'\.py(?:/\S+)?$', request.path):
            # While not dangerous per se, we never serve *.py files as static
            raise NotFound
        try:
            return send_from_directory(current_app.config['INDICO_HTDOCS'], request.path[1:], conditional=True)
        except (UnicodeEncodeError, BadRequest):
            raise NotFound
    except NotFound:
        if exception.description == NotFound.description:
            # The default reason is too long and not localized
            description = _("The page you are looking for doesn't exist.")
        else:
            description = exception.description
        return render_error(_("Page not found"), description), 404

Example 32

Project: netman
Source File: netman_api.py
View license
    def api_docs(self, filename=None):
        """
        Shows this documentation

        """
        return send_from_directory(os.path.dirname(__file__) + "/doc/html/", filename or "index.html")

Example 33

Project: amivapi
Source File: media.py
View license
@download.route('/storage/<filename>', methods=['GET'])
def download_file(filename):
    """Send a file.

    TODO (Alex): Maybe better use new eve method?
    """
    if not common_authorization('storage', 'GET'):
        abort(401)
    return send_from_directory(app.config['STORAGE_DIR'], filename)

Example 34

Project: Flask-Transfer
Source File: app.py
View license
@app.route('/pdf/<pdf>')
def display_pdf(pdf):
    path = utils.get_save_path(pdf)
    if not os.path.exists(path):
        abort(404)
    else:
        return send_from_directory(*os.path.split(path))

Example 35

Project: Flask-Transfer
Source File: app.py
View license
@app.route('/pdf/<pdf>')
def display_pdf(pdf):
    path = utils.get_save_path(pdf)
    if not os.path.exists(path):
        abort(404)
    else:
        return send_from_directory(*os.path.split(path))

Example 36

Project: gavel
Source File: default.py
View license
@app.route('/favicon.ico')
def favicon():
    return send_from_directory(
        os.path.join(app.root_path, 'static'),
        'favicon.ico',
        mimetype='image/vnd.microsoft.icon'
    )

Example 37

Project: gavel
Source File: default.py
View license
@app.route('/favicon.ico')
def favicon():
    return send_from_directory(
        os.path.join(app.root_path, 'static'),
        'favicon.ico',
        mimetype='image/vnd.microsoft.icon'
    )

Example 38

Project: deep-landmark
Source File: app.py
View license
@app.route('/media/result/<path>')
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 39

Project: deep-landmark
Source File: app.py
View license
@app.route('/media/result/<path>')
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 40

Project: festival
Source File: subsonic.py
View license
@subsonic.route('/rest/getCoverArt.view', methods=['GET', 'POST'])
@typed_fct
def cover_art(typed):
    eid = request.args.get('id')
    cid = clean_id(eid)
    if not is_track_id(eid) and not is_album_id(eid):
        return request.error_formatter(10, 'Invalid id')

    if is_track_id(eid):
        tr = typed.gettrackinfo(cid)
        if tr is None or tr.album_id is None:
            return request.error_formatter(70, 'Cover art not found'), 404
        else:
            cid = tr.album_id
    cover = typed.getcoverbyalbumid(cid)
    if cover is None or cover.mbid == '0':
        return request.error_formatter(70, 'Cover art not found'), 404
    else:
        return send_from_directory(Thumb.getdir(), os.path.basename(cover.path), conditional=True)

Example 41

Project: festival
Source File: subsonic.py
View license
@subsonic.route('/rest/getCoverArt.view', methods=['GET', 'POST'])
@typed_fct
def cover_art(typed):
    eid = request.args.get('id')
    cid = clean_id(eid)
    if not is_track_id(eid) and not is_album_id(eid):
        return request.error_formatter(10, 'Invalid id')

    if is_track_id(eid):
        tr = typed.gettrackinfo(cid)
        if tr is None or tr.album_id is None:
            return request.error_formatter(70, 'Cover art not found'), 404
        else:
            cid = tr.album_id
    cover = typed.getcoverbyalbumid(cid)
    if cover is None or cover.mbid == '0':
        return request.error_formatter(70, 'Cover art not found'), 404
    else:
        return send_from_directory(Thumb.getdir(), os.path.basename(cover.path), conditional=True)

Example 42

Project: festival
Source File: routes.py
View license
@routes.route("/albumart/<salbum>")
@typed_fct
def albumart(typed, salbum):
    cover = typed.getcoverbyalbumid(salbum)
    if cover is None or cover.mbid == '0':
        return redirect(url_for('static', filename='images/nocover.png'))
    else:
        return send_from_directory(Thumb.getdir(), os.path.basename(cover.path), conditional=True)

Example 43

Project: festival
Source File: routes.py
View license
@routes.route("/albumart/<salbum>")
@typed_fct
def albumart(typed, salbum):
    cover = typed.getcoverbyalbumid(salbum)
    if cover is None or cover.mbid == '0':
        return redirect(url_for('static', filename='images/nocover.png'))
    else:
        return send_from_directory(Thumb.getdir(), os.path.basename(cover.path), conditional=True)

Example 44

Project: mailinabox
Source File: daemon.py
View license
@app.route('/munin/')
@app.route('/munin/<path:filename>')
@authorized_personnel_only
def munin(filename=""):
	# Checks administrative access (@authorized_personnel_only) and then just proxies
	# the request to static files.
	if filename == "": filename = "index.html"
	return send_from_directory("/var/cache/munin/www", filename)

Example 45

Project: mailinabox
Source File: daemon.py
View license
@app.route('/munin/')
@app.route('/munin/<path:filename>')
@authorized_personnel_only
def munin(filename=""):
	# Checks administrative access (@authorized_personnel_only) and then just proxies
	# the request to static files.
	if filename == "": filename = "index.html"
	return send_from_directory("/var/cache/munin/www", filename)

Example 46

Project: gmusicprocurator
Source File: ui.py
View license
@app.route('/favicon.ico')
def favicon():
    """
    favicon.ico route.

    From: http://flask.pocoo.org/docs/patterns/favicon/
    """
    return send_from_directory(os.path.join(app.root_path, 'static'),
                               'favicon.ico', mimetype=ICO_MIMETYPE)

Example 47

Project: gmusicprocurator
Source File: ui.py
View license
@app.route('/favicon.ico')
def favicon():
    """
    favicon.ico route.

    From: http://flask.pocoo.org/docs/patterns/favicon/
    """
    return send_from_directory(os.path.join(app.root_path, 'static'),
                               'favicon.ico', mimetype=ICO_MIMETYPE)

Example 48

Project: master-server
Source File: server.py
View license
@app.route("/list")
def list():
	# We have to make sure that the list isn't cached,
	# since the list isn't really static.
	return send_from_directory(app.static_folder, "list.json",
			cache_timeout=0)

Example 49

Project: master-server
Source File: server.py
View license
@app.route("/list")
def list():
	# We have to make sure that the list isn't cached,
	# since the list isn't really static.
	return send_from_directory(app.static_folder, "list.json",
			cache_timeout=0)

Example 50

Project: build-relengapi
Source File: __init__.py
View license
@bp.route('/static', defaults={'path': ''})
@bp.route('/static/<path:path>')
def static(path):
    # the Blueprint's static_folder can't depend on app configuration, so we
    # just implement static files directly
    support = get_support()
    return send_from_directory(support.staticdir, path)