本文整理汇总了Python中app.create_app方法的典型用法代码示例。如果您正苦于以下问题:Python app.create_app方法的具体用法?Python app.create_app怎么用?Python app.create_app使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app
的用法示例。
在下文中一共展示了app.create_app方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: app
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def app(request):
"""Creates a flask.Flask app with the 'development' config/context.
:request: test request
:returns: flask.Flask object
"""
app = create_app('development')
ctx = app.app_context()
ctx.push()
def tear_down():
ctx.pop()
request.addfinalizer(tear_down)
return app
示例2: create_app
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def create_app():
app = _create_app()
@app.shell_context_processor
def make_shell_context():
return dict(
app=app,
db=db,
create_db=create_db,
drop_db=drop_db,
UserModel=UserModel,
create_user=create_user,
PostModel=PostModel,
TagModel=TagModel
)
print(app.url_map)
print(app.config)
return app
示例3: setUpClass
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def setUpClass(cls):
# start Firefox
try:
cls.client = webdriver.Firefox()
except:
pass
if cls.client:
cls.app = create_app('testing')
cls.app_context = cls.app.app_context()
cls.app_context.push()
db.drop_all()
db.create_all()
todo = Todo(title='title1', body='body1')
db.session.add(todo)
db.session.commit()
threading.Thread(target=cls.app.run).start()
示例4: setUp
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
Role.insert_roles()
self.client = self.app.test_client()
示例5: setUp
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
Role.insert_roles()
示例6: setUp
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
示例7: setUpClass
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def setUpClass(cls):
# start Chrome
try:
cls.client = webdriver.Chrome(service_args=["--verbose", "--log-path=test-reports/chrome.log"])
except:
pass
# skip these tests if the browser could not be started
if cls.client:
# create the application
cls.app = create_app('testing')
cls.app_context = cls.app.app_context()
cls.app_context.push()
# suppress logging to keep unittest output clean
import logging
logger = logging.getLogger('werkzeug')
logger.setLevel("ERROR")
# create the database and populate with some fake data
db.create_all()
Role.insert_roles()
User.generate_fake(10)
Post.generate_fake(10)
# add an administrator user
admin_role = Role.query.filter_by(permissions=0xff).first()
admin = User(email='john@example.com',
username='john', password='cat',
role=admin_role, confirmed=True)
db.session.add(admin)
db.session.commit()
# start the Flask server in a thread
threading.Thread(target=cls.app.run).start()
# give the server a second to ensure it is up
time.sleep(1)
示例8: setUp
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def setUp(self):
self.app = create_app('testing')
self.app_context = self.app.app_context()
self.app_context.push()
db.create_all()
Role.insert_roles()
self.client = self.app.test_client(use_cookies=True)
示例9: setUp
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def setUp(self):
self.app = create_app(LocalLevelConfig, LocalDBConfig)
self.client = self.app.test_client()
self.method = "GET"
self.path = None
self.path_parameters = dict()
self.headers = dict()
self.json = dict()
self.query_string = dict()
示例10: export
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def export(context, output_format='json', quiet=False):
"""
Export swagger.json content
"""
# set logging level to ERROR to avoid [INFO] messages in result
logging.getLogger().setLevel(logging.ERROR)
from app import create_app
app = create_app(flask_config_name='testing')
swagger_content = app.test_client().get('/api/v1/swagger.%s' % output_format).data
if not quiet:
print(swagger_content.decode('utf-8'))
return swagger_content
示例11: enter
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def enter(context, install_dependencies=True, upgrade_db=True):
"""
Enter into IPython notebook shell with an initialized app.
"""
if install_dependencies:
context.invoke_execute(context, 'app.dependencies.install')
if upgrade_db:
context.invoke_execute(context, 'app.db.upgrade')
context.invoke_execute(
context,
'app.db.init_development_data',
upgrade_db=False,
skip_on_failure=True
)
import pprint
from werkzeug import script
import flask
import app
flask_app = app.create_app()
def shell_context():
context = dict(pprint=pprint.pprint)
context.update(vars(flask))
context.update(vars(app))
return context
with flask_app.app_context():
script.make_shell(shell_context, use_ipython=True)()
示例12: app_context_task
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def app_context_task(*args, **kwargs):
"""
A helper Invoke Task decorator with auto app context activation.
Examples:
>>> @app_context_task
... def my_task(context, some_arg, some_option='default'):
... print("Done")
>>> @app_context_task(
... help={'some_arg': "This is something useful"}
... )
... def my_task(context, some_arg, some_option='default'):
... print("Done")
"""
if len(args) == 1:
func = args[0]
@functools.wraps(func)
def wrapper(*args, **kwargs):
"""
A wrapped which tries to get ``app`` from ``kwargs`` or creates a
new ``app`` otherwise, and actives the application context, so the
decorated function is run inside the application context.
"""
app = kwargs.pop('app', None)
if app is None:
from app import create_app
app = create_app()
with app.app_context():
return func(*args, **kwargs)
# This is the default in Python 3, so we just make it backwards
# compatible with Python 2
if not hasattr(wrapper, '__wrapped__'):
wrapper.__wrapped__ = func
return Task(wrapper, **kwargs)
return lambda func: app_context_task(func, **kwargs)
示例13: flask_app
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def flask_app():
app = create_app(flask_config_name='testing')
from app.extensions import db
with app.app_context():
db.create_all()
yield app
db.drop_all()
示例14: app
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def app():
app = create_app(config_file='config/testing.py')
app.response_class = ApiTestingResponse
ctx = app.app_context()
ctx.push()
yield app
ctx.pop()
示例15: setUp
# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def setUp(self):
app = create_app()
self.app = app.test_client()