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 151

Project: disco-dop
Source File: parse.py
View license
@APP.route('/parser/static/style.css')
def stylecss():
	"""Serve style.css."""
	return send_from_directory(os.path.join(APP.root_path, 'static'),
			'style.css', mimetype='text/css')

Example 152

Project: disco-dop
Source File: treedraw.py
View license
@APP.route('/favicon.ico')
def favicon():
	""" Serve the favicon. """
	return send_from_directory(os.path.join(APP.root_path, 'static'),
			'treesearch.ico', mimetype='image/vnd.microsoft.icon')

Example 153

Project: disco-dop
Source File: parse.py
View license
@APP.route('/parser/favicon.ico')
def favicon():
	"""Serve the favicon."""
	return send_from_directory(os.path.join(APP.root_path, 'static'),
			'parse.ico', mimetype='image/vnd.microsoft.icon')

Example 154

Project: disco-dop
Source File: treedraw.py
View license
def drawtrees(form, dts):
	""" Draw trees in the requested format. """
	if form.get('output', 'text') == 'svg':
		if len(dts) == 1:
			return Response(dts[0].svg(
						funcsep='-' if 'func' in request.args else None,
						).encode('utf8'), mimetype='image/svg+xml')
		else:
			preamble, postamble = DrawTree.templates['svg']
			result = [preamble.encode('utf8')]
			for dt in dts:
				result.append(
						('<div>\n%s\n</div>\n\n' % dt.svg(
						funcsep='-' if 'func' in request.args else None,
							)).encode('utf8'))
			result.append(postamble.encode('utf8'))
			return Response(b'\n'.join(result), mimetype='text/html')
	elif form.get('output', 'text') == 'text':
		html = form.get('color', False)
		useascii = not form.get('unicode', 0)
		preamble, postamble = DrawTree.templates['html']
		result = []
		if html:
			mimetype = 'text/html'
			result.append(preamble.encode('utf8'))
		else:
			mimetype = 'text/plain'
		for dt in dts:
			result.append(
					dt.text(unicodelines=not useascii, html=html,
						funcsep='-' if 'func' in request.args else None,
						).encode('utf8'))
		if html:
			result.append(postamble.encode('utf8'))
		return Response(b'\n'.join(result), mimetype=mimetype)

	# LaTeX based output
	if form.get('type', None) == 'qtree':
		preamble, postamble = DrawTree.templates['latex']
		for dt in dts:
			for pos in dt.tree.subtrees(lambda n: n and isinstance(n[0], int)):
				pos[0] = dt.sent[pos[0]]
		latexcode = (preamble + '\n\n'.join(dt.tikzqtree() for dt in dts)
				+ postamble)
	elif form.get('type', 'matrix') == 'matrix':
		preamble, postamble = DrawTree.templates['latex']
		latexcode = (preamble + '\n\n'.join(
				dt.tikzmatrix(
						leafcolor=('blue' if form.get('color', '') else ''),
						nodecolor=('red' if form.get('color', '') else ''),
						funcsep='-' if 'func' in request.args else None)
				for dt in dts) + postamble)
	else:
		preamble, postamble = DrawTree.templates['latex']
		latexcode = (preamble + '\n\n'.join(
				dt.tikznode(
						leafcolor='blue' if form.get('color', '') else '',
						nodecolor='red' if form.get('color', '') else '',
						funcsep='-' if 'func' in request.args else None)
				for dt in dts) + postamble)
	if form.get('output', 'text') == 'latex':
		return Response(latexcode, mimetype='text/plain')
	with io.open('/tmp/dtree.tex', 'w', encoding='utf8') as tex:
		tex.write(latexcode)
	os.chdir('/tmp')
	proc = Popen('/usr/bin/pdflatex -halt-on-error  /tmp/dtree.tex'.split(),
			stdin=None, stdout=PIPE, stderr=PIPE, shell=False)
	proc.wait()
	if form.get('output', 'text') == 'pdf':
		try:
			return send_from_directory('/tmp', 'dtree.pdf',
					mimetype='application/pdf')
		except IOError:
			pass
		for ext in ('aux', 'log', 'pdf'):
			os.remove('/tmp/dtree.' + ext)
	if form.get('output', 'text') == 'png':
		proc = Popen('/usr/bin/convert -density 125 /tmp/dtree.pdf \
				/tmp/dtree.png'.split(),  # -trim
				stdin=None, stdout=PIPE, stderr=PIPE, shell=False)
		proc.wait()
		# set Expires one day ahead (according to server time)
		# req.headers_out['Expires'] = (
		# 	datetime.utcnow() + timedelta( 1, 0 )
		# 	).strftime('%a, %d %b %Y %H:%M:%S UTC')
		# req.headers_out['Cache-Control'] = 'max-age=604800, public'
		try:
			return send_from_directory('/tmp', 'dtree.png',
					mimetype='image/png')
		except IOError:
			pass
		for filename in ('/tmp/dtree.aux', '/tmp/dtree.log',
				'/tmp/dtree.tex', '/tmp/dtree.pdf', '/tmp/dtree.png'):
			try:
				os.remove(filename)
			except OSError:
				break

Example 155

Project: disco-dop
Source File: parse.py
View license
@APP.route('/parser/static/main.js')
def javascript():
	"""Serve javascript."""
	return send_from_directory(os.path.join(APP.root_path, 'static'),
			'main.js', mimetype='text/javascript')

Example 156

Project: disco-dop
Source File: parse.py
View license
@APP.route('/parser/static/style.css')
def stylecss():
	"""Serve style.css."""
	return send_from_directory(os.path.join(APP.root_path, 'static'),
			'style.css', mimetype='text/css')

Example 157

Project: disco-dop
Source File: treedraw.py
View license
@APP.route('/favicon.ico')
def favicon():
	""" Serve the favicon. """
	return send_from_directory(os.path.join(APP.root_path, 'static'),
			'treesearch.ico', mimetype='image/vnd.microsoft.icon')

Example 158

Project: disco-dop
Source File: treedraw.py
View license
def drawtrees(form, dts):
	""" Draw trees in the requested format. """
	if form.get('output', 'text') == 'svg':
		if len(dts) == 1:
			return Response(dts[0].svg(
						funcsep='-' if 'func' in request.args else None,
						).encode('utf8'), mimetype='image/svg+xml')
		else:
			preamble, postamble = DrawTree.templates['svg']
			result = [preamble.encode('utf8')]
			for dt in dts:
				result.append(
						('<div>\n%s\n</div>\n\n' % dt.svg(
						funcsep='-' if 'func' in request.args else None,
							)).encode('utf8'))
			result.append(postamble.encode('utf8'))
			return Response(b'\n'.join(result), mimetype='text/html')
	elif form.get('output', 'text') == 'text':
		html = form.get('color', False)
		useascii = not form.get('unicode', 0)
		preamble, postamble = DrawTree.templates['html']
		result = []
		if html:
			mimetype = 'text/html'
			result.append(preamble.encode('utf8'))
		else:
			mimetype = 'text/plain'
		for dt in dts:
			result.append(
					dt.text(unicodelines=not useascii, html=html,
						funcsep='-' if 'func' in request.args else None,
						).encode('utf8'))
		if html:
			result.append(postamble.encode('utf8'))
		return Response(b'\n'.join(result), mimetype=mimetype)

	# LaTeX based output
	if form.get('type', None) == 'qtree':
		preamble, postamble = DrawTree.templates['latex']
		for dt in dts:
			for pos in dt.tree.subtrees(lambda n: n and isinstance(n[0], int)):
				pos[0] = dt.sent[pos[0]]
		latexcode = (preamble + '\n\n'.join(dt.tikzqtree() for dt in dts)
				+ postamble)
	elif form.get('type', 'matrix') == 'matrix':
		preamble, postamble = DrawTree.templates['latex']
		latexcode = (preamble + '\n\n'.join(
				dt.tikzmatrix(
						leafcolor=('blue' if form.get('color', '') else ''),
						nodecolor=('red' if form.get('color', '') else ''),
						funcsep='-' if 'func' in request.args else None)
				for dt in dts) + postamble)
	else:
		preamble, postamble = DrawTree.templates['latex']
		latexcode = (preamble + '\n\n'.join(
				dt.tikznode(
						leafcolor='blue' if form.get('color', '') else '',
						nodecolor='red' if form.get('color', '') else '',
						funcsep='-' if 'func' in request.args else None)
				for dt in dts) + postamble)
	if form.get('output', 'text') == 'latex':
		return Response(latexcode, mimetype='text/plain')
	with io.open('/tmp/dtree.tex', 'w', encoding='utf8') as tex:
		tex.write(latexcode)
	os.chdir('/tmp')
	proc = Popen('/usr/bin/pdflatex -halt-on-error  /tmp/dtree.tex'.split(),
			stdin=None, stdout=PIPE, stderr=PIPE, shell=False)
	proc.wait()
	if form.get('output', 'text') == 'pdf':
		try:
			return send_from_directory('/tmp', 'dtree.pdf',
					mimetype='application/pdf')
		except IOError:
			pass
		for ext in ('aux', 'log', 'pdf'):
			os.remove('/tmp/dtree.' + ext)
	if form.get('output', 'text') == 'png':
		proc = Popen('/usr/bin/convert -density 125 /tmp/dtree.pdf \
				/tmp/dtree.png'.split(),  # -trim
				stdin=None, stdout=PIPE, stderr=PIPE, shell=False)
		proc.wait()
		# set Expires one day ahead (according to server time)
		# req.headers_out['Expires'] = (
		# 	datetime.utcnow() + timedelta( 1, 0 )
		# 	).strftime('%a, %d %b %Y %H:%M:%S UTC')
		# req.headers_out['Cache-Control'] = 'max-age=604800, public'
		try:
			return send_from_directory('/tmp', 'dtree.png',
					mimetype='image/png')
		except IOError:
			pass
		for filename in ('/tmp/dtree.aux', '/tmp/dtree.log',
				'/tmp/dtree.tex', '/tmp/dtree.pdf', '/tmp/dtree.png'):
			try:
				os.remove(filename)
			except OSError:
				break

Example 159

Project: disco-dop
Source File: treesearch.py
View license
@APP.route('/favicon.ico')
def favicon():
	"""Serve the favicon."""
	return send_from_directory(os.path.join(APP.root_path, 'static'),
			'treesearch.ico', mimetype='image/vnd.microsoft.icon')

Example 160

Project: disco-dop
Source File: treesearch.py
View license
@APP.route('/favicon.ico')
def favicon():
	"""Serve the favicon."""
	return send_from_directory(os.path.join(APP.root_path, 'static'),
			'treesearch.ico', mimetype='image/vnd.microsoft.icon')

Example 161

Project: kcsrv
Source File: init.py
View license
def init(app):
    # --> Jinja2 Env Update
    app.jinja_env.globals.update(__builtins__=__builtins__)

    # --> URI setup
    app.config["SQLALCHEMY_DATABASE_URI"] = \
        "postgresql://{}:{}@{}:{}/{}".format(app.config["DB_USERNAME"], app.config["DB_PASSWORD"],
                                             app.config["DB_HOSTNAME"], app.config["DB_PORT"],
                                             app.config["DB_DATABASE"])

    # --> Extension setup
    db.init_app(app)
    admin.init_app(app)
    mail = Mail()
    mail.init_app(app)

    modules["migrate"] = Migrate(app, db)

    modules["user_datastore"] = SQLAlchemyUserDatastore(db, User, Role)
    modules["security"] = Security(app, modules["user_datastore"], confirm_register_form=MyRegisterForm)

    # --> Admiral load on each request
    def admiral_load():
        api_token = request.values.get('api_token', None)
        if api_token is None:
            logger.warning("No API Key -> Skipping request")
            abort(403)
        user = db.session.query(User).filter(User.api_token == api_token).first()
        if user is None:
            logger.warning("Unknown API Key -> {}".format(api_token))
            abort(404)
        g.admiral = user.admiral if user.admiral else Admiral().create(user)
        # Update resources.
        curr_t = datetime.datetime.utcnow()
        lastaction = g.admiral.last_action
        if not lastaction:
            lastaction = curr_t
        delta = (curr_t - lastaction).total_seconds() / 60
        if delta < 0:
            # wat
            logger.warn("Now - lastaction for admiral {} negative?".format(user.nickname))
            return
        delta = int(delta)
        g.admiral.resources.add(*((delta * 3) for _ in range(3)), baux=delta * 2)
        # Update action time
        g.admiral.last_action = curr_t
        db.session.add(g.admiral)
        db.session.commit()

    # --> Set up blueprints
    from kancolle.api import api_actions

    api_actions.before_request(admiral_load)

    app.register_blueprint(api_actions, url_prefix='/kcsapi')

    from kancolle.api import api_member

    api_member.before_request(admiral_load)

    app.register_blueprint(api_member, url_prefix='/kcsapi/api_get_member')

    from kancolle.api import api_init

    api_init.before_request(admiral_load)

    app.register_blueprint(api_init, url_prefix='/kcsapi')

    from kancolle.api import api_user

    api_user.before_request(admiral_load)

    app.register_blueprint(api_user, url_prefix='/kcsapi')

    from kancolle.api import api_mission

    api_mission.before_request(admiral_load)

    app.register_blueprint(api_mission, url_prefix='/kcsapi/api_req_mission')

    @app.route('/play')
    def p_index():
        if hasattr(current_user, 'api_token'):
            api_token = current_user.api_token
            return render_template('play/index.html', api_token=api_token)
        else:
            return redirect('/account/login')

    # --> Base application routes
    @app.route('/')
    def index():
        return render_template('index.html')

    @app.route('/kcs/<path:path>')
    def kcs(path):
        return send_from_directory('kcs', path)

    # --> Signals
    @user_logged_in.connect_via(app)
    def u_logged_in(sender, user):
        """
        Regenerate the API token every login.
        """
        user.api_token = generate_api_token()

Example 162

Project: kcsrv
Source File: init.py
View license
def init(app):
    # --> Jinja2 Env Update
    app.jinja_env.globals.update(__builtins__=__builtins__)

    # --> URI setup
    app.config["SQLALCHEMY_DATABASE_URI"] = \
        "postgresql://{}:{}@{}:{}/{}".format(app.config["DB_USERNAME"], app.config["DB_PASSWORD"],
                                             app.config["DB_HOSTNAME"], app.config["DB_PORT"],
                                             app.config["DB_DATABASE"])

    # --> Extension setup
    db.init_app(app)
    admin.init_app(app)
    mail = Mail()
    mail.init_app(app)

    modules["migrate"] = Migrate(app, db)

    modules["user_datastore"] = SQLAlchemyUserDatastore(db, User, Role)
    modules["security"] = Security(app, modules["user_datastore"], confirm_register_form=MyRegisterForm)

    # --> Admiral load on each request
    def admiral_load():
        api_token = request.values.get('api_token', None)
        if api_token is None:
            logger.warning("No API Key -> Skipping request")
            abort(403)
        user = db.session.query(User).filter(User.api_token == api_token).first()
        if user is None:
            logger.warning("Unknown API Key -> {}".format(api_token))
            abort(404)
        g.admiral = user.admiral if user.admiral else Admiral().create(user)
        # Update resources.
        curr_t = datetime.datetime.utcnow()
        lastaction = g.admiral.last_action
        if not lastaction:
            lastaction = curr_t
        delta = (curr_t - lastaction).total_seconds() / 60
        if delta < 0:
            # wat
            logger.warn("Now - lastaction for admiral {} negative?".format(user.nickname))
            return
        delta = int(delta)
        g.admiral.resources.add(*((delta * 3) for _ in range(3)), baux=delta * 2)
        # Update action time
        g.admiral.last_action = curr_t
        db.session.add(g.admiral)
        db.session.commit()

    # --> Set up blueprints
    from kancolle.api import api_actions

    api_actions.before_request(admiral_load)

    app.register_blueprint(api_actions, url_prefix='/kcsapi')

    from kancolle.api import api_member

    api_member.before_request(admiral_load)

    app.register_blueprint(api_member, url_prefix='/kcsapi/api_get_member')

    from kancolle.api import api_init

    api_init.before_request(admiral_load)

    app.register_blueprint(api_init, url_prefix='/kcsapi')

    from kancolle.api import api_user

    api_user.before_request(admiral_load)

    app.register_blueprint(api_user, url_prefix='/kcsapi')

    from kancolle.api import api_mission

    api_mission.before_request(admiral_load)

    app.register_blueprint(api_mission, url_prefix='/kcsapi/api_req_mission')

    @app.route('/play')
    def p_index():
        if hasattr(current_user, 'api_token'):
            api_token = current_user.api_token
            return render_template('play/index.html', api_token=api_token)
        else:
            return redirect('/account/login')

    # --> Base application routes
    @app.route('/')
    def index():
        return render_template('index.html')

    @app.route('/kcs/<path:path>')
    def kcs(path):
        return send_from_directory('kcs', path)

    # --> Signals
    @user_logged_in.connect_via(app)
    def u_logged_in(sender, user):
        """
        Regenerate the API token every login.
        """
        user.api_token = generate_api_token()

Example 163

Project: permanote
Source File: views.py
View license
@application.route('/uploads/<filename>')
def uploaded_file(filename):
    return send_from_directory(application.config['UPLOAD_FOLDER'],
                               filename)

Example 164

Project: permanote
Source File: views.py
View license
@application.route('/uploads/<filename>')
def uploaded_file(filename):
    return send_from_directory(application.config['UPLOAD_FOLDER'],
                               filename)

Example 165

View license
@app.route('/api/distances.json')
def news():
  return flask.send_from_directory('model', 'distances.json')

Example 166

View license
@app.route('/api/distances.json')
def news():
  return flask.send_from_directory('model', 'distances.json')

Example 167

Project: redwind
Source File: views.py
View license
def render_attachment(post, filename):
    if not post:
        current_app.logger.warn('no post found')
        abort(404)

    if post.deleted:
        abort(410)  # deleted permanently

    if not check_audience(post):
        abort(401)

    attachment = next(
        (a for a in post.attachments if a.filename == filename), None)

    if not attachment:
        current_app.logger.warn('no attachment named %s', filename)
        abort(404)

    current_app.logger.debug('image file path: %s. request args: %s',
                             attachment.disk_path, request.args)

    if not os.path.exists(attachment.disk_path):
        current_app.logger.warn('source path does not exist %s',
                                attachment.disk_path)
        abort(404)

    if current_app.debug:
        _, ext = os.path.splitext(attachment.disk_path)
        return send_from_directory(
            os.path.dirname(attachment.disk_path),
            os.path.basename(attachment.disk_path),
            mimetype=attachment.mimetype)

    resp = make_response('')
    # nginx is configured to serve internal resources directly
    resp.headers['X-Accel-Redirect'] = os.path.join(
        '/internal_data', attachment.storage_path)
    resp.headers['Content-Type'] = attachment.mimetype
    del resp.headers['Content-Length']
    current_app.logger.debug('response with X-Accel-Redirect %s', resp.headers)
    return resp

Example 168

Project: redwind
Source File: views.py
View license
def render_attachment(post, filename):
    if not post:
        current_app.logger.warn('no post found')
        abort(404)

    if post.deleted:
        abort(410)  # deleted permanently

    if not check_audience(post):
        abort(401)

    attachment = next(
        (a for a in post.attachments if a.filename == filename), None)

    if not attachment:
        current_app.logger.warn('no attachment named %s', filename)
        abort(404)

    current_app.logger.debug('image file path: %s. request args: %s',
                             attachment.disk_path, request.args)

    if not os.path.exists(attachment.disk_path):
        current_app.logger.warn('source path does not exist %s',
                                attachment.disk_path)
        abort(404)

    if current_app.debug:
        _, ext = os.path.splitext(attachment.disk_path)
        return send_from_directory(
            os.path.dirname(attachment.disk_path),
            os.path.basename(attachment.disk_path),
            mimetype=attachment.mimetype)

    resp = make_response('')
    # nginx is configured to serve internal resources directly
    resp.headers['X-Accel-Redirect'] = os.path.join(
        '/internal_data', attachment.storage_path)
    resp.headers['Content-Type'] = attachment.mimetype
    del resp.headers['Content-Length']
    current_app.logger.debug('response with X-Accel-Redirect %s', resp.headers)
    return resp

Example 169

Project: Flask-Scaffold
Source File: __init__.py
View license
def create_app(config_filename):
    app = Flask(__name__, static_folder='templates/static')
    app.config.from_object(config_filename)

    # Init Flask-SQLAlchemy
    from app.basemodels import db
    db.init_app(app)   

    from app.baseviews import login_required, login1, mail
    from flask import render_template, send_from_directory
    import os

    # Init Flask-Mail
    mail.init_app(app)

    @app.route('/login')
    def login():
        return render_template('login.html')

    @app.route('/<path:filename>')
    def file(filename):
        return send_from_directory(os.path.join(app.root_path, 'templates'), filename)

    @app.route('/')
    def index():
        return render_template('index.html')

    # Auth API
    app.register_blueprint(login1, url_prefix='/api/v1/')

    from app.roles.views import roles
    app.register_blueprint(roles, url_prefix='/api/v1/roles')
    
    from app.users.views import users
    app.register_blueprint(users, url_prefix='/api/v1/users')

    # Blueprints
  

    return app

Example 170

Project: Flask-Scaffold
Source File: __init__.py
View license
def create_app(config_filename):
    app = Flask(__name__, static_folder='templates/static')
    app.config.from_object(config_filename)

    # Init Flask-SQLAlchemy
    from app.basemodels import db
    db.init_app(app)   

    from app.baseviews import login_required, login1, mail
    from flask import render_template, send_from_directory
    import os

    # Init Flask-Mail
    mail.init_app(app)

    @app.route('/login')
    def login():
        return render_template('login.html')

    @app.route('/<path:filename>')
    def file(filename):
        return send_from_directory(os.path.join(app.root_path, 'templates'), filename)

    @app.route('/')
    def index():
        return render_template('index.html')

    # Auth API
    app.register_blueprint(login1, url_prefix='/api/v1/')

    from app.roles.views import roles
    app.register_blueprint(roles, url_prefix='/api/v1/roles')
    
    from app.users.views import users
    app.register_blueprint(users, url_prefix='/api/v1/users')

    # Blueprints
  

    return app

Example 171

Project: balrog
Source File: base.py
View license
@app.route('/robots.txt')
def robots():
    return send_from_directory(app.static_folder, "robots.txt")

Example 172

Project: balrog
Source File: base.py
View license
@app.route('/robots.txt')
def robots():
    return send_from_directory(app.static_folder, "robots.txt")

Example 173

Project: wifiportal21
Source File: auth_server.py
View license
@auth_app.route('/static/<path:path>')
@auth_app.route('/js/<path:path>')
def static_jquery(path):
    return flask.send_from_directory(auth_app.static_folder, path)

Example 174

Project: snapstore
Source File: store.py
View license
@app.route('/download/<name>')
def download(name):
    return send_from_directory(FILES, name)

Example 175

Project: yuyushiki
Source File: yuyushiki.py
View license
@app.route('/data/<path:filename>')
def data(filename):
    return send_from_directory(root.as_posix(), filename)

Example 176

Project: yuyushiki
Source File: yuyushiki.py
View license
@app.route('/img/<path:filename>')
def img(filename):
    return send_from_directory('img', filename)

Example 177

Project: yuyushiki
Source File: yuyushiki.py
View license
@app.route('/js/lib/<path:filename>')
def js(filename):
    return send_from_directory('templates/lib', filename)

Example 178

Project: yuyushiki
Source File: yuyushiki.py
View license
@app.route('/data/<path:filename>')
def data(filename):
    return send_from_directory(root.as_posix(), filename)

Example 179

Project: yuyushiki
Source File: yuyushiki.py
View license
@app.route('/img/<path:filename>')
def img(filename):
    return send_from_directory('img', filename)

Example 180

Project: yuyushiki
Source File: yuyushiki.py
View license
@app.route('/js/lib/<path:filename>')
def js(filename):
    return send_from_directory('templates/lib', filename)

Example 181

Project: Open-Notify-API
Source File: app.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 182

Project: udata
Source File: app.py
View license
    def send_static_file(self, filename):
        '''
        Override default static handling:
        - raises 404 if not debug
        - handle static aliases
        '''
        if not self.debug:
            self.logger.error('Static files are only served in debug')
            abort(404)

        cache_timeout = self.get_send_file_max_age(filename)

        # Default behavior
        if isfile(join(self.static_folder, filename)):
            return send_from_directory(self.static_folder, filename,
                                       cache_timeout=cache_timeout)

        # Handle aliases
        for prefix, directory in self.config.get('STATIC_DIRS', tuple()):
            if filename.startswith(prefix):
                real_filename = filename[len(prefix):]
                if real_filename.startswith('/'):
                    real_filename = real_filename[1:]
                if isfile(join(directory, real_filename)):
                    return send_from_directory(directory, real_filename,
                                               cache_timeout=cache_timeout)
        abort(404)

Example 183

Project: udata
Source File: views.py
View license
@noI18n.route('/robots.txt')
def static_from_root():
    return send_from_directory(current_app.static_folder, request.path[1:])

Example 184

View license
@app.route('/static/<path:path>')
def send_js(path):
    # TODO: We should probably use a real webserver for this..
    return send_from_directory('static', path)

Example 185

Project: bombolone
Source File: content.py
View license
@content.route('/robots.txt/')
@content.route('/sitemap.xml/')
@content.route('/favicon.ico/')
def static_from_root():
    return send_from_directory(current_app.static_folder, request.path[1:])

Example 186

Project: geomancer
Source File: views.py
View license
@views.route('/download/<path:filename>')
def download_results(filename):
    return send_from_directory(current_app.config['RESULT_FOLDER'], filename)

Example 187

Project: gxgk-wechat-server
Source File: routes.py
View license
@app.route('/robots.txt')
def robots():
    """搜索引擎爬虫协议"""
    return send_from_directory(app.static_folder, request.path[1:])

Example 188

Project: AstroBox
Source File: __init__.py
View license
@app.route("/robots.txt")
def robotsTxt():
	return send_from_directory(app.static_folder, "robots.txt")

Example 189

Project: AstroBox
Source File: __init__.py
View license
@app.route("/favicon.ico")
def favion():
	return send_from_directory(app.static_folder, "favicon.ico")

Example 190

Project: AstroBox
Source File: __init__.py
View license
@app.route("/apple-touch-icon.png")
def apple_icon():
	return send_from_directory(app.static_folder, "apple-touch-icon.png")