本文整理汇总了Python中flask.app.Flask方法的典型用法代码示例。如果您正苦于以下问题:Python app.Flask方法的具体用法?Python app.Flask怎么用?Python app.Flask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.app
的用法示例。
在下文中一共展示了app.Flask方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_authentication
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def set_authentication(application: Flask, authentication: bool) -> Iterator:
"""
Set the whether API needs to be authenticated or not (before it is run in main.py).
:param application: Flask app object
<flask.app.Flask>
:param authentication : Bool. API Auth needed or not
<bool>
Raises:
TypeError: If `authentication` is not a boolean value.
"""
if not isinstance(authentication, bool):
raise TypeError("Authentication flag must be of type <bool>")
def handler(sender: Flask, **kwargs: Any) -> None:
g.authentication_ = authentication
with appcontext_pushed.connected_to(handler, application):
yield
示例2: set_api_name
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def set_api_name(application: Flask, api_name: str) -> Iterator:
"""
Set the server name or EntryPoint for the app (before it is run in main.py).
:param application: Flask app object
<flask.app.Flask>
:param api_name : API/Server name or EntryPoint
<str>
Raises:
TypeError: If `api_name` is not a string.
"""
if not isinstance(api_name, str):
raise TypeError("The api_name is not of type <str>")
def handler(sender: Flask, **kwargs: Any) -> None:
g.api_name = api_name
with appcontext_pushed.connected_to(handler, application):
yield
示例3: set_page_size
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def set_page_size(application: Flask, page_size: int) -> Iterator:
"""
Set the page_size of a page view.
:param application: Flask app object
<flask.app.Flask>
:param page_size : Number of maximum elements a page can contain
<int>
Raises:
TypeError: If `page_size` is not an int.
"""
if not isinstance(page_size, int):
raise TypeError("The page_size is not of type <int>")
def handler(sender: Flask, **kwargs: Any) -> None:
g.page_size = page_size
with appcontext_pushed.connected_to(handler, application):
yield
示例4: set_pagination
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def set_pagination(application: Flask, paginate: bool) -> Iterator:
"""
Enable or disable pagination.
:param application: Flask app object
<flask.app.Flask>
:param paginate : Pagination enabled or not
<bool>
Raises:
TypeError: If `paginate` is not a bool.
"""
if not isinstance(paginate, bool):
raise TypeError("The CLI argument 'pagination' is not of type <bool>")
def handler(sender: Flask, **kwargs: Any) -> None:
g.paginate = paginate
with appcontext_pushed.connected_to(handler, application):
yield
示例5: set_doc
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def set_doc(application: Flask, APIDOC: HydraDoc) -> Iterator:
"""
Set the API Documentation for the app (before it is run in main.py).
:param application: Flask app object
<flask.app.Flask>
:param APIDOC : Hydra Documentation object
<hydra_python_core.doc_writer.HydraDoc>
Raises:
TypeError: If `APIDOC` is not an instance of `HydraDoc`.
"""
if not isinstance(APIDOC, HydraDoc):
raise TypeError(
"The API Doc is not of type <hydra_python_core.doc_writer.HydraDoc>")
def handler(sender: Flask, **kwargs: Any) -> None:
g.doc = APIDOC
with appcontext_pushed.connected_to(handler, application):
yield
示例6: set_hydrus_server_url
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def set_hydrus_server_url(application: Flask, server_url: str) -> Iterator:
"""
Set the server URL for the app (before it is run in main.py).
:param application: Flask app object
<flask.app.Flask>
:param server_url : Server URL
<str>
Raises:
TypeError: If the `server_url` is not a string.
"""
if not isinstance(server_url, str):
raise TypeError("The server_url is not of type <str>")
def handler(sender: Flask, **kwargs: Any) -> None:
g.hydrus_server_url = server_url
with appcontext_pushed.connected_to(handler, application):
yield
示例7: set_session
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def set_session(application: Flask, DB_SESSION: scoped_session) -> Iterator:
"""
Set the Database Session for the app before it is run in main.py.
:param application: Flask app object
<flask.app.Flask>
:param DB_SESSION: SQLalchemy Session object
<sqlalchemy.orm.session.Session>
Raises:
TypeError: If `DB_SESSION` is not an instance of `scoped_session` or `Session`.
"""
if not isinstance(DB_SESSION, scoped_session) and not isinstance(
DB_SESSION, Session):
raise TypeError(
"The API Doc is not of type <sqlalchemy.orm.session.Session> or"
" <sqlalchemy.orm.scoping.scoped_session>")
def handler(sender: Flask, **kwargs: Any) -> None:
g.dbsession = DB_SESSION
with appcontext_pushed.connected_to(handler, application):
yield
示例8: oidc_provider_init_app
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def oidc_provider_init_app(config_file, name=None, **kwargs):
name = name or __name__
app = Flask(name, static_url_path='', **kwargs)
app.rp_config = Configuration.create_from_config_file(config_file)
# Session key for the application session
app.config['SECRET_KEY'] = os.urandom(12).hex()
app.users = {'test_user': {'name': 'Testing Name'}}
try:
from .views import oidc_rp_views
except ImportError:
from views import oidc_rp_views
app.register_blueprint(oidc_rp_views)
# Initialize the oidc_provider after views to be able to set correct urls
app.rph = init_oidc_rp_handler(app)
return app
示例9: create_app
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def create_app(self):
from openbrokerapi.api import get_blueprint
app = Flask(__name__)
self.broker = Mock()
app.register_blueprint(
get_blueprint(self.broker,
BrokerCredentials("", ""),
basic_config(level=logging.WARN)
)
)
return app
示例10: config
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def config(self, app):
if not is_connexion_present():
raise RuntimeError("connexion is not available in system runtime")
from flask.app import Flask
if not isinstance(app.app, Flask):
raise RuntimeError("app is not a valid connexion.app.Connexion app instance")
# Disable standard logging
logging.getLogger('werkzeug').disabled = True
json_logging.util.update_formatter_for_loggers([logging.getLogger('werkzeug')], JSONLogWebFormatter)
# noinspection PyAttributeOutsideInit
self.request_logger = logging.getLogger('connexion-request-logger')
from flask import g
@app.app.before_request
def before_request():
g.request_info = json_logging.RequestInfo(_current_request)
@app.app.after_request
def after_request(response):
request_info = g.request_info
request_info.update_response_status(response)
self.request_logger.info("", extra={'request_info': request_info})
return response
示例11: config
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def config(self, app):
if not is_flask_present():
raise RuntimeError("flask is not available in system runtime")
from flask.app import Flask
if not isinstance(app, Flask):
raise RuntimeError("app is not a valid flask.app.Flask app instance")
# Disable standard logging
logging.getLogger('werkzeug').disabled = True
json_logging.util.update_formatter_for_loggers([logging.getLogger('werkzeug')],
json_logging.JSONLogWebFormatter)
# noinspection PyAttributeOutsideInit
self.request_logger = logging.getLogger('flask-request-logger')
from flask import g
@app.before_request
def before_request():
g.request_info = json_logging.RequestInfo(_current_request)
@app.after_request
def after_request(response):
request_info = g.request_info
request_info.update_response_status(response)
self.request_logger.info("", extra={'request_info': request_info})
return response
示例12: oidc_provider_init_app
# 需要导入模块: from flask import app [as 别名]
# 或者: from flask.app import Flask [as 别名]
def oidc_provider_init_app(name=None):
name = name or __name__
app = Flask(name)
app.config.from_pyfile('application.cfg')
app.users = {'test_user': {'name': 'Testing Name'}}
from .views import oidc_provider_views
app.register_blueprint(oidc_provider_views)
# Initialize the oidc_provider after views to be able to set correct urls
app.provider = init_oidc_provider(app)
return app