當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。