當前位置: 首頁>>代碼示例>>Python>>正文


Python flask.send_from_directory方法代碼示例

本文整理匯總了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

################################## 
開發者ID:janeczku,項目名稱:calibre-web,代碼行數:27,代碼來源:helper.py

示例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) 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:18,代碼來源:webserver_sub.py

示例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) 
開發者ID:dmsimard,項目名稱:ara-archive,代碼行數:24,代碼來源:webapp.py

示例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() 
開發者ID:tonysyu,項目名稱:matplotlib-style-gallery,代碼行數:24,代碼來源:app.py

示例5: send_favicon

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import send_from_directory [as 別名]
def send_favicon():
    return send_from_directory(STATIC, 'favicon.ico') 
開發者ID:chubin,項目名稱:rate.sx,代碼行數:4,代碼來源:srv.py

示例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) 
開發者ID:CboeSecurity,項目名稱:password_pwncheck,代碼行數:9,代碼來源:password-pwncheck.py

示例7: send_static

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import send_from_directory [as 別名]
def send_static(path):
    return send_from_directory(STATIC, path) 
開發者ID:chubin,項目名稱:rate.sx,代碼行數:4,代碼來源:srv.py

示例8: send_malformed

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import send_from_directory [as 別名]
def send_malformed():
    return send_from_directory(STATIC, 'malformed-response.html') 
開發者ID:chubin,項目名稱:rate.sx,代碼行數:4,代碼來源:srv.py

示例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 
開發者ID:dissemin,項目名稱:oabot,代碼行數:11,代碼來源:app.py

示例10: send_edits

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import send_from_directory [as 別名]
def send_edits(path):
    return flask.send_from_directory('edits', path) 
開發者ID:dissemin,項目名稱:oabot,代碼行數:4,代碼來源:app.py

示例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:]) 
開發者ID:smallwat3r,項目名稱:shhh,代碼行數:5,代碼來源:views.py

示例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 
開發者ID:TomFaulkner,項目名稱:SenseMe,代碼行數:9,代碼來源:flask_app.py

示例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) 
開發者ID:cristianpb,項目名稱:object-detection,代碼行數:28,代碼來源:app.py

示例14: status

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import send_from_directory [as 別名]
def status():
    return send_from_directory('../dist', "index.html") 
開發者ID:cristianpb,項目名稱:object-detection,代碼行數:4,代碼來源:app.py

示例15: build

# 需要導入模塊: import flask [as 別名]
# 或者: from flask import send_from_directory [as 別名]
def build(path):
    return send_from_directory('../dist', path) 
開發者ID:cristianpb,項目名稱:object-detection,代碼行數:4,代碼來源:app.py


注:本文中的flask.send_from_directory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。