本文整理汇总了Python中flask.send_from_directory方法的典型用法代码示例。如果您正苦于以下问题:Python flask.send_from_directory方法的具体用法?Python flask.send_from_directory怎么用?Python flask.send_from_directory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask
的用法示例。
在下文中一共展示了flask.send_from_directory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_download_file
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
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
##################################
示例2: send_data
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
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)
示例3: configure_static_route
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
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)
示例4: _add_url_rules
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
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()
示例5: send_favicon
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
def send_favicon():
return send_from_directory(STATIC, 'favicon.ico')
示例6: StaticRequests
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
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)
示例7: send_static
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
def send_static(path):
return send_from_directory(STATIC, path)
示例8: send_malformed
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
def send_malformed():
return send_from_directory(STATIC, 'malformed-response.html')
示例9: send_static
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
def send_static(path):
print("path: {}".format(path))
try:
return flask.send_from_directory('static', path)
except Exception as e:
print("path: {}".format(path))
with open('exception', 'w') as f:
f.write(str(type(e))+' '+str(e))
return
示例10: send_edits
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
def send_edits(path):
return flask.send_from_directory('edits', path)
示例11: robots
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
def robots():
"""Robots handler."""
return send_from_directory(app.static_folder, request.path[1:])
示例12: index
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
def index():
# return flask.send_from_directory('./static/', 'index.html')
flask.flash(str((fan.speed, fan.brightness)))
return flask.render_template("index.html")
# Light Functions
示例13: image_preview
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
def image_preview(filename):
w = request.args.get('w', None)
h = request.args.get('h', None)
date = request.args.get('date', None)
try:
im = cv2.imread(os.path.join(IMAGE_FOLDER, filename))
if w and h:
w, h = int(w), int(h)
im = cv2.resize(im, (w, h))
elif date:
date = (datetime
.strptime(date, "%Y%m%d_%H%M%S")
.strftime("%d %b %-H:%M")
)
img_h, img_w = im.shape[:-1]
cv2.putText(
im, "{}".format(date), (0, int(img_h*0.98)),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
return Response(cv2.imencode('.jpg', im)[1].tobytes(),
mimetype='image/jpeg')
except Exception as e:
print(e)
return send_from_directory('.', filename)
示例14: status
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
def status():
return send_from_directory('../dist', "index.html")
示例15: build
# 需要导入模块: import flask [as 别名]
# 或者: from flask import send_from_directory [as 别名]
def build(path):
return send_from_directory('../dist', path)