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


Python current_app.app_context方法代码示例

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


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

示例1: test_template_filters

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def test_template_filters():
    template = """
        Dollar: {{ 0.1 | dollar }}<br>
        Sum Key: {{ data | sum_key('col') }}<br>
        Max Key: {{ data | max_key('col') }}<br>
        Average Key: {{ data | average_key('col') }}<br>
    """

    data = [
        dict(col=0),
        dict(col=0.5),
        dict(col=0.5),
        dict(col=1),
    ]

    with current_app.app_context():
        html = render_template_string(template, data=data)

    assert 'Dollar: $0.10<br>' in html
    assert 'Sum Key: 2.0<br>' in html
    assert 'Max Key: 1<br>' in html
    assert 'Average Key: 0.5<br>' in html 
开发者ID:Robpol86,项目名称:Flask-Large-Application-Example,代码行数:24,代码来源:test_middleware.py

示例2: test_client

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def test_client():
    flask_app = create_app()

    # Flask provides a way to test your application by exposing the Werkzeug test Client
    # and handling the context locals for you.
    testing_client = flask_app.test_client()

    # Establish an application context before running the tests.
    ctx = flask_app.app_context()
    ctx.push()

    from flask import g
    g.pending_transactions = []
    g.executor_jobs = []

    yield testing_client  # this is where the testing happens!

    ctx.pop() 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:20,代码来源:conftest.py

示例3: init_database

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def init_database():
    # Create the database and the database table

    with current_app.app_context():
        db.create_all()

    yield db  # this is where the testing happens!

    with current_app.app_context():
        try:
            db.session.execute('DROP MATERIALIZED VIEW IF EXISTS search_view;')
            db.session.commit()
        except:
            pass
        db.session.remove()  # DO NOT DELETE THIS LINE. We need to close sessions before dropping tables.
        db.drop_all() 
开发者ID:teamsempo,项目名称:SempoBlockchain,代码行数:18,代码来源:conftest.py

示例4: inject_span_in_headers

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def inject_span_in_headers(headers):
    if has_request_context():
        # FLASK https://github.com/opentracing-contrib/python-flask
        tracer = current_app.tracer if getattr(current_app, "tracer") else None
        # Add traces
        span = None
        current_app.app_context()
        if tracer:
            span = tracer.get_span(request=request)
            if not span:  # pragma: no cover
                span = get_current_span()
                if not span:
                    span = tracer.tracer.start_span()
            context = span.context if span else None
            tracer.tracer.inject(context, opentracing.Format.HTTP_HEADERS, headers)
    return headers 
开发者ID:python-microservices,项目名称:pyms,代码行数:18,代码来源:tracer.py

示例5: start

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def start(self):
        # TODO(dcramer): we should probably move the log capture up to this
        # level so we *always* get full/correct logs
        assert not self.active, "TaskRunner already started"
        self.active = True
        self._started = time()
        self._process = Popen(
            args=["bin/run-task", str(self.task.id)],
            cwd=PROJECT_ROOT,
            stdout=PIPE,
            stderr=STDOUT,
        )
        self._logreporter = LogReporter(
            app_context=current_app.app_context(),
            task_id=self.task.id,
            process=self._process,
        )
        self._logreporter.start()

    # TODO(dcramer): currently this is the sum of checks + job time which
    # isnt ideal. We either could move checks into execute_task and have a new
    # timeout just for them, or assume this timeout includes both and likely
    # still add another timeout for checks 
开发者ID:getsentry,项目名称:freight,代码行数:25,代码来源:execute_task.py

示例6: plugin

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [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

示例7: save

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def save(self, check_status=True, **kwargs):
        # While used in async method, app context is not available by default
        # and needs to be imported
        from flask import current_app as app
        from kqueen.server import create_app
        try:
            if not app.testing:
                app = create_app()
        except RuntimeError:
            app = create_app()

        with app.app_context():
            if check_status:
                self.state = self.engine_status(save=False)
            self.verbose_name = getattr(self.get_engine_cls(), 'verbose_name', self.engine)
            return super().save(**kwargs)


#
# AUTHENTICATION
# 
开发者ID:Mirantis,项目名称:kqueen,代码行数:23,代码来源:models.py

示例8: refresh_email_settings

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def refresh_email_settings():
    """
    Load the current app context mail settings.

    Called to make sure that the current thread/worker has the newest
    email settings from the database.
    """
    with current_app.app_context():
        settings = api.config.get_settings()
        if settings["email"]["enable_email"]:
            current_app.config["MAIL_SUPPRESS_SEND"] = False
            current_app.config["MAIL_SERVER"] = settings["email"]["smtp_url"]
            current_app.config["MAIL_PORT"] = settings["email"]["smtp_port"]
            current_app.config["MAIL_USERNAME"] = settings["email"]["email_username"]
            current_app.config["MAIL_PASSWORD"] = settings["email"]["email_password"]
            current_app.config["MAIL_DEFAULT_SENDER"] = settings["email"]["from_addr"]
            if settings["email"]["smtp_security"] == "TLS":
                current_app.config["MAIL_USE_TLS"] = True
                current_app.config["MAIL_USE_SSL"] = False
            elif settings["email"]["smtp_security"] == "SSL":
                current_app.config["MAIL_USE_TLS"] = False
                current_app.config["MAIL_USE_SSL"] = True
        else:
            # Use a testing configuration
            current_app.config["MAIL_SUPPRESS_SEND"] = True
            current_app.config["MAIL_DEFAULT_SENDER"] = "testing@picoctf.com"
    mail.init_app(current_app) 
开发者ID:picoCTF,项目名称:picoCTF,代码行数:29,代码来源:email.py

示例9: _generate_access_token

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def _generate_access_token(self):
        with app.app_context():
            expires = datetime.timedelta(days=365)
            access_token = create_access_token(self.id, expires_delta=expires)
            # access_token = create_access_token(self.id)
            return access_token 
开发者ID:MaxGoh,项目名称:Flask-GraphQL-Graphene-MySQL-Docker-StarterKit,代码行数:8,代码来源:User.py

示例10: _generate_refresh_token

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def _generate_refresh_token(self):
        with app.app_context():
            refresh_token = create_refresh_token(self.id)
            return refresh_token 
开发者ID:MaxGoh,项目名称:Flask-GraphQL-Graphene-MySQL-Docker-StarterKit,代码行数:6,代码来源:User.py

示例11: flask_app_context

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def flask_app_context():
    """
    celery使用Flask上下文
    :return:
    """
    with current_app.app_context():
        return str(current_app.config) 
开发者ID:qzq1111,项目名称:flask-restful-example,代码行数:9,代码来源:celery.py

示例12: __init__

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def __init__(self, app_context, task_id, process, chunk_size=4096):
        self.app_context = app_context
        self.task_id = task_id
        self.process = process
        self.chunk_size = chunk_size
        self.cur_offset = 0
        self.last_recv = None
        self.active = True
        threading.Thread.__init__(self)
        self.daemon = True
        self.write_lock = threading.Lock() 
开发者ID:getsentry,项目名称:freight,代码行数:13,代码来源:execute_task.py

示例13: run

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def run(self):
        with self.app_context:
            self._run() 
开发者ID:getsentry,项目名称:freight,代码行数:5,代码来源:execute_task.py

示例14: get_books_queue

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def get_books_queue():
    project = current_app.config['PROJECT_ID']

    # Create a queue specifically for processing books and pass in the
    # Flask application context. This ensures that tasks will have access
    # to any extensions / configuration specified to the app, such as
    # models.
    return psq.Queue(
        publisher_client, subscriber_client, project,
        'books', extra_context=current_app.app_context) 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-python,代码行数:12,代码来源:tasks.py

示例15: html

# 需要导入模块: from flask import current_app [as 别名]
# 或者: from flask.current_app import app_context [as 别名]
def html(self, groups='all', template=None, **context):
        """Return an html string of the routes specified by the doc() method

        A template can be specified. A list of routes is available under the
        'autodoc' value (refer to the documentation for the generate() for a
        description of available values). If no template is specified, a
        default template is used.

        By specifying the group or groups arguments, only routes belonging to
        those groups will be returned.
        """
        if template:
            return render_template(template,
                                   autodoc=self.generate(groups=groups),
                                   **context)
        else:
            filename = os.path.join(
                os.path.dirname(__file__),
                'templates',
                'autodoc_default.html'
            )
            with open(filename) as file:
                content = file.read()
                with current_app.app_context():
                    return render_template_string(
                        content,
                        autodoc=self.generate(groups=groups),
                        **context) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:30,代码来源:autodoc.py


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