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


Python app.create_app方法代码示例

本文整理汇总了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 
开发者ID:alexandre-old,项目名称:flask-rest-template,代码行数:20,代码来源:conftest.py

示例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 
开发者ID:fushall,项目名称:myblog,代码行数:21,代码来源:manage.py

示例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() 
开发者ID:vahidR,项目名称:restful-todo,代码行数:23,代码来源:test_integration.py

示例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() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:9,代码来源:test_api.py

示例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() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:8,代码来源:test_user_model.py

示例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() 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:7,代码来源:test_basics.py

示例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) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:40,代码来源:test_selenium.py

示例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) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:9,代码来源:test_client.py

示例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() 
开发者ID:JoMingyu,项目名称:Flask-Large-Application-Example,代码行数:13,代码来源:__init__.py

示例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 
开发者ID:frol,项目名称:flask-restplus-server-example,代码行数:15,代码来源:swagger.py

示例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)() 
开发者ID:frol,项目名称:flask-restplus-server-example,代码行数:34,代码来源:env.py

示例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) 
开发者ID:frol,项目名称:flask-restplus-server-example,代码行数:43,代码来源:_utils.py

示例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() 
开发者ID:frol,项目名称:flask-restplus-server-example,代码行数:10,代码来源:conftest.py

示例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() 
开发者ID:sunscrapers,项目名称:flask-boilerplate,代码行数:11,代码来源:conftest.py

示例15: setUp

# 需要导入模块: import app [as 别名]
# 或者: from app import create_app [as 别名]
def setUp(self):
        app = create_app()
        self.app = app.test_client() 
开发者ID:njbbaer,项目名称:unicorn-remote,代码行数:5,代码来源:test_api.py


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