当前位置: 首页>>代码示例>>Python>>正文


Python current_app.root_path方法代码示例

本文整理汇总了Python中flask.current_app.root_path方法的典型用法代码示例。如果您正苦于以下问题:Python current_app.root_path方法的具体用法?Python current_app.root_path怎么用?Python current_app.root_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.current_app的用法示例。


在下文中一共展示了current_app.root_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_file

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def load_file(self, filename):
        """
        Load the filename from the local directory. The type of the returned
        object depends on if the filename corresponds to a file or a directory.
        If it's a file, a flask Response object containing the file's data will
        be returned. If it's a directory, a gopher menu will be returned.

        This method uses the flask application context, which means that it
        can only be invoked from inside of a flask view.
        """
        abs_filename = safe_join(self.local_directory, filename)
        if not os.path.isabs(abs_filename):
            abs_filename = os.path.join(current_app.root_path, abs_filename)

        if os.path.isfile(abs_filename):
            return self.result_class(False, send_file(abs_filename))
        elif os.path.isdir(abs_filename):
            data = self._parse_directory(filename, abs_filename)
            return self.result_class(True, data)
        else:
            raise BadRequest() 
开发者ID:michael-lazar,项目名称:flask-gopher,代码行数:23,代码来源:flask_gopher.py

示例2: setup

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def setup(obj):
    log.info('setting up fixtures...')

    # Push a request and/or app context onto the stack
    push_ctx(getattr(obj, 'app'))

    # Setup the database
    obj.db.create_all()
    # Rollback any lingering transactions
    obj.db.session.rollback()


    # Construct a list of paths within which fixtures may reside
    default_fixtures_dir = os.path.join(current_app.root_path, 'fixtures')

    # All relative paths should be relative to the app's root directory.
    fixtures_dirs = [default_fixtures_dir]
    for directory in current_app.config.get('FIXTURES_DIRS', []):
        if not os.path.isabs(directory):
            directory = os.path.abspath(os.path.join(current_app.root_path, directory))
        fixtures_dirs.append(directory)

    # Load all of the fixtures
    for filename in obj.fixtures:
        load_fixtures_from_file(obj.db, filename, fixtures_dirs) 
开发者ID:croach,项目名称:Flask-Fixtures,代码行数:27,代码来源:__init__.py

示例3: get_conf_json

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def get_conf_json(path, file):
    """
    通用: 获取 JSON 配置文件

    :param path: 相对于 conf, e.g. bgp
    :param file: 文件名, 不带扩展名, e.g. as-name
    :return: dict,e.g. {'123': '成都'}
    """
    ret = {}
    file = os.path.join(current_app.root_path, 'conf', path, file + '.json')

    try:
        with open(file, 'r', encoding='utf-8') as f:
            ret = json.load(f)
    except Exception as e:
        current_app.logger.error('{0!r} {1}'.format(e, file))

    return ret 
开发者ID:fufuok,项目名称:FF.PyAdmin,代码行数:20,代码来源:__init__.py

示例4: plugin

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def plugin(plugin):
    if request.method == "GET":
        plugins_path = os.path.join(app.root_path, "plugins")

        config_html_plugins = [
            name
            for name in os.listdir(plugins_path)
            if os.path.isfile(os.path.join(plugins_path, name, "config.html"))
        ]

        if plugin in config_html_plugins:
            config_html = open(
                os.path.join(app.root_path, "plugins", plugin, "config.html")
            ).read()
            return render_template_string(config_html)
        abort(404)
    elif request.method == "POST":
        for k, v in request.form.items():
            if k == "nonce":
                continue
            set_config(k, v)
        with app.app_context():
            clear_config()
        return "1" 
开发者ID:CTFd,项目名称:CTFd,代码行数:26,代码来源:__init__.py

示例5: calendar_dir

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def calendar_dir() -> str:
    """获得日历文件路径。生产环境为/var/calendar_files/,否则为程序根目录下的calendar_files文件夹。"""
    if get_env() == "PRODUCTION":
        return "/var/calendar_files/"
    return (current_app.root_path or "") + "/../../calendar_files/" 
开发者ID:everyclass,项目名称:everyclass-server,代码行数:7,代码来源:ics_generator.py

示例6: _exist_config

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def _exist_config(app):
    filename = "{}/config.py".format(app.root_path)
    return os.path.exists(filename) 
开发者ID:chaijunit,项目名称:beibq,代码行数:5,代码来源:start.py

示例7: create_config

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def create_config(username, password, host, db):
    data = render_template("admin/start/config.html", username=username,
        password=password, host=host, db = db)
    filename = '{}/config.py'.format(current_app.root_path)
    fd = open(filename, "w")
    fd.write(data)
    fd.close() 
开发者ID:chaijunit,项目名称:beibq,代码行数:9,代码来源:start.py

示例8: create_path

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def create_path(app):
    paths, config = [], app.config
    log_path, _ = os.path.split(config["ERROR_LOG"])
    paths.append(os.path.join(app.root_path, log_path))

    paths.append(os.path.join(app.static_folder, config["AVATAR_PATH"]))
    paths.append(os.path.join(app.static_folder, config["TMP_PATH"]))
    paths.append(os.path.join(app.static_folder, config["IMAGE_PATH"]))
    paths.append(os.path.join(app.static_folder, config["BOOK_COVER_PATH"]))
    for path in paths:
        if not os.path.exists(path):
            os.makedirs(path) 
开发者ID:chaijunit,项目名称:beibq,代码行数:14,代码来源:start.py

示例9: swagger_spec

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def swagger_spec():
    try:
        spec_path = os.path.join(current_app.root_path, "swagger-spec.yaml")
        spec = open(spec_path, 'r')
        loaded_spec = load(spec.read(), Loader)
    except Exception as e:
        current_app.logger.error(
            'Cannot view swagger spec. Error: {0}'.format(e))
        current_app.logger.debug(traceback.format_exc())
        abort(500)

    resp = make_response(json.dumps(loaded_spec), 200)
    resp.headers['Content-Type'] = 'application/json'

    return resp 
开发者ID:ngoduykhanh,项目名称:PowerDNS-Admin,代码行数:17,代码来源:index.py

示例10: home

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def home():
    filename = request.form['filename']
    filename=filename.replace('../','')
    if os.path.isfile(current_app.root_path + '/'+ filename):
        with current_app.open_resource(filename) as f:
            read = f.read()
    else: 
        read='try harder'
    return render_template("index.html",read = read) 
开发者ID:blabla1337,项目名称:skf-labs,代码行数:11,代码来源:LFI-2.py

示例11: home

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def home():
    filename = urllib.parse.unquote(request.form['filename'])
    read='try harder...'
    if '../' not in filename:
        filename = urllib.parse.unquote(filename)
        if os.path.isfile(current_app.root_path + '/'+ filename):
            with current_app.open_resource(filename) as f:
                read = f.read()
    return render_template("index.html",read = read) 
开发者ID:blabla1337,项目名称:skf-labs,代码行数:11,代码来源:LFI-3.py

示例12: themes

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def themes(theme, path):
    """
    General static file handler
    :param theme:
    :param path:
    :return:
    """
    filename = safe_join(app.root_path, "themes", theme, "static", path)
    if os.path.isfile(filename):
        return send_file(filename)
    else:
        abort(404) 
开发者ID:CTFd,项目名称:CTFd,代码行数:14,代码来源:views.py

示例13: stamp_latest_revision

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def stamp_latest_revision():
    # Get proper migrations directory regardless of cwd
    directory = os.path.join(os.path.dirname(app.root_path), "migrations")
    stamp(directory=directory) 
开发者ID:CTFd,项目名称:CTFd,代码行数:6,代码来源:__init__.py

示例14: get_themes

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def get_themes():
    dir = os.path.join(app.root_path, "themes")
    return [
        name
        for name in os.listdir(dir)
        if os.path.isdir(os.path.join(dir, name)) and name != "admin"
    ] 
开发者ID:CTFd,项目名称:CTFd,代码行数:9,代码来源:__init__.py

示例15: build_url

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import root_path [as 别名]
def build_url(component, filename, **values):
    """
    search bower asset and build url

    :param component: bower component (package)
    :type component: str
    :param filename: filename in bower component - can contain directories (like dist/jquery.js)
    :type filename: str
    :param values: additional url parameters
    :type values: dict[str, str]
    :return: url
    :rtype: str | None
    """
    root = current_app.config['BOWER_COMPONENTS_ROOT']
    bower_data = None
    package_data = None

    # check if component exists in bower_components directory
    if not os.path.isdir(os.path.join(current_app.root_path, root, component)):
        # FallBack to default url_for flask
        return None

    # load bower.json of specified component
    bower_file_path = os.path.join(current_app.root_path, root, component, 'bower.json')
    if os.path.exists(bower_file_path):
        with open(bower_file_path, 'r') as bower_file:
            bower_data = json.load(bower_file)

    # check if package.json exists and load package.json data
    package_file_path = os.path.join(current_app.root_path, root, component, 'package.json')
    if os.path.exists(package_file_path):
        with open(package_file_path, 'r') as package_file:
            package_data = json.load(package_file)

    # check if specified file actually exists
    if not os.path.exists(os.path.join(current_app.root_path, root, component, filename)):
        return None

    # check if minified file exists (by pattern <filename>.min.<ext>
    # returns filename if successful
    if current_app.config['BOWER_TRY_MINIFIED']:
        if '.min.' not in filename:
            minified_filename = '%s.min.%s' % tuple(filename.rsplit('.', 1))
            minified_path = os.path.join(root, component, minified_filename)

            if os.path.exists(os.path.join(current_app.root_path, minified_path)):
                filename = minified_filename

    # determine version of component and append as ?version= parameter to allow cache busting
    if current_app.config['BOWER_QUERYSTRING_REVVING']:
        if bower_data is not None and 'version' in bower_data:
            values['version'] = bower_data['version']
        elif package_data is not None and 'version' in package_data:
            values['version'] = package_data['version']
        else:
            values['version'] = os.path.getmtime(os.path.join(current_app.root_path, root, component, filename))

    return url_for('bower.serve', component=component, filename=filename, **values) 
开发者ID:lobeck,项目名称:flask-bower,代码行数:60,代码来源:__init__.py


注:本文中的flask.current_app.root_path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。