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


Python MongoEngine.init_app方法代码示例

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


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

示例1: setUp

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
    def setUp(self):
        super(JSONAppTestCase, self).setUp()
        self.app.config['MONGODB_DB'] = 'testing'
        self.app.config['TESTING'] = True
        db = MongoEngine()

        class Todo(db.Document):
            title = db.StringField(max_length=60)
            text = db.StringField()
            done = db.BooleanField(default=False)
            pub_date = db.DateTimeField(default=datetime.datetime.now)

        db.init_app(self.app)

        Todo.drop_collection()
        self.Todo = Todo

        @self.app.route('/')
        def index():
            return flask.jsonify(result=self.Todo.objects())

        @self.app.route('/add', methods=['POST'])
        def add():
            form = flask.request.form
            todo = self.Todo(title=form['title'],
                             text=form['text'])
            todo.save()
            return flask.jsonify(result=todo)

        @self.app.route('/show/<id>/')
        def show(id):
            return flask.jsonify(result=self.Todo.objects.get_or_404(id=id))

        self.db = db
开发者ID:mtsgrd,项目名称:flask-mongoengine,代码行数:36,代码来源:test_json_app.py

示例2: setUp

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
    def setUp(self):
        app = flask.Flask(__name__)
        app.config['MONGODB_DB'] = 'testing'
        app.config['TESTING'] = True
        db = MongoEngine()
        self.Todo = make_todo_model(db)

        db.init_app(app)

        self.Todo.drop_collection()

        @app.route('/')
        def index():
            return '\n'.join(x.title for x in self.Todo.objects)

        @app.route('/add', methods=['POST'])
        def add():
            form = flask.request.form
            todo = self.Todo(title=form['title'],
                             text=form['text'])
            todo.save()
            return 'added'

        @app.route('/show/<id>/')
        def show(id):
            todo = self.Todo.objects.get_or_404(id=id)
            return '\n'.join([todo.title, todo.text])

        self.app = app
        self.db = db
开发者ID:DYFeng,项目名称:flask-mongoengine,代码行数:32,代码来源:tests.py

示例3: setUp

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
    def setUp(self):
        super(BasicAppTestCase, self).setUp()
        db = MongoEngine()

        class Todo(db.Document):
            title = db.StringField(max_length=60)
            text = db.StringField()
            done = db.BooleanField(default=False)
            pub_date = db.DateTimeField(default=datetime.datetime.now)

        db.init_app(self.app)

        Todo.drop_collection()
        self.Todo = Todo

        @self.app.route('/')
        def index():
            return '\n'.join(x.title for x in self.Todo.objects)

        @self.app.route('/add', methods=['POST'])
        def add():
            form = flask.request.form
            todo = self.Todo(title=form['title'],
                             text=form['text'])
            todo.save()
            return 'added'

        @self.app.route('/show/<id>/')
        def show(id):
            todo = self.Todo.objects.get_or_404(id=id)
            return '\n'.join([todo.title, todo.text])

        self.db = db
开发者ID:brunobelarmino,项目名称:flask-mongoengine,代码行数:35,代码来源:test_basic_app.py

示例4: setUp

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
 def setUp(self):
     super(JSONAppTestCase, self).setUp()
     self.app.config['MONGODB_DB'] = 'testing'
     self.app.config['TESTING'] = True
     self.app.json_encoder = DummyEncoder
     db = MongoEngine()
     db.init_app(self.app)
     self.db = db
开发者ID:871392231,项目名称:flask-mongoengine,代码行数:10,代码来源:test_json.py

示例5: test_connection_kwargs_with_false_values

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
 def test_connection_kwargs_with_false_values(self):
     self.app.config['MONGODB_SETTINGS'] = {
         'DB': 'testing',
         'alias': 'test',
         'use_greenlets': False
     }
     self.app.config['TESTING'] = True
     db = MongoEngine()
     db.init_app(self.app)
     self.assertFalse(db.connection.use_greenlets)
开发者ID:AlmogCohen,项目名称:flask-mongoengine,代码行数:12,代码来源:test_json_app.py

示例6: test_connection_default

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
    def test_connection_default(self):
        self.app.config['MONGODB_SETTINGS'] = {}
        self.app.config['TESTING'] = True

        db = MongoEngine()
        db.init_app(self.app)

        self.app.config['TESTING'] = True
        db = MongoEngine()
        db.init_app(self.app)
开发者ID:brunobelarmino,项目名称:flask-mongoengine,代码行数:12,代码来源:test_basic_app.py

示例7: setUp

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
    def setUp(self):
        app = flask.Flask(__name__)
        app.config['MONGODB_DB'] = 'testing'
        app.config['TESTING'] = True
        app.json_encoder = DummyEncoder
        db = MongoEngine()
        db.init_app(app)

        self.app = app
        self.db = db
开发者ID:andrewelkins,项目名称:flask-mongoengine,代码行数:12,代码来源:test_json.py

示例8: test_connection_default

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
    def test_connection_default(self):
        app = flask.Flask(__name__)
        app.config['MONGODB_SETTINGS'] = {}
        app.config['TESTING'] = True

        db = MongoEngine()
        db.init_app(app)

        app.config['TESTING'] = True
        db = MongoEngine()
        db.init_app(app)
开发者ID:andrewelkins,项目名称:flask-mongoengine,代码行数:13,代码来源:test_basic_app.py

示例9: setup

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
def setup():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = '1'
    app.config['CSRF_ENABLED'] = False
    app.config['MONGODB_SETTINGS'] = {'DB': 'tests'}

    db = MongoEngine()
    db.init_app(app)

    admin = Admin(app)

    return app, db, admin
开发者ID:hellwen,项目名称:pyservice,代码行数:14,代码来源:__init__.py

示例10: test_connection_db_only

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
    def test_connection_db_only(self):
        app = flask.Flask(__name__)
        app.config['MONGODB_SETTINGS'] = {
            'db': 'test'
        }
        app.config['TESTING'] = True
        db = MongoEngine()
        db.init_app(app)

        app.config['MONGODB_DB'] = 'test'
        app.config['TESTING'] = True
        db = MongoEngine()
        db.init_app(app)
开发者ID:corydolphin,项目名称:flask-mongoengine,代码行数:15,代码来源:test_basic_app.py

示例11: test_connection_kwargs_as_list

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
 def test_connection_kwargs_as_list(self):
     self.app.config['MONGODB_SETTINGS'] = [{
         'DB': 'testing_tz_aware',
         'alias': 'tz_aware_true',
         'TZ_AWARE': True
     }, {
         'DB': 'testing_tz_aware_off',
         'alias': 'tz_aware_false',
         'TZ_AWARE': False
     }]
     self.app.config['TESTING'] = True
     db = MongoEngine()
     db.init_app(self.app)
     self.assertTrue(db.connection['tz_aware_true'].tz_aware)
     self.assertFalse(db.connection['tz_aware_false'].tz_aware)
开发者ID:871392231,项目名称:flask-mongoengine,代码行数:17,代码来源:test_basic_app.py

示例12: test_connection_kwargs

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
    def test_connection_kwargs(self):
        app = flask.Flask(__name__)
        app.config['MONGODB_SETTINGS'] = {
            'DB': 'testing_tz_aware',
            'alias': 'tz_aware_true',
            'TZ_AWARE': True,
        }
        app.config['TESTING'] = True
        db = MongoEngine()
        db.init_app(app)
        self.assertTrue(db.connection.tz_aware)

        app.config['MONGODB_SETTINGS'] = {
            'DB': 'testing',
            'alias': 'tz_aware_false',
        }
        db.init_app(app)
        self.assertFalse(db.connection.tz_aware)
开发者ID:Frozen,项目名称:flask-mongoengine,代码行数:20,代码来源:test_basic_app.py

示例13: test_connection_kwargs

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
    def test_connection_kwargs(self):
        self.app.config['MONGODB_SETTINGS'] = {
            'DB': 'testing_tz_aware',
            'ALIAS': 'tz_aware_true',
            'TZ_AWARE': True
        }
        self.app.config['TESTING'] = True
        db = MongoEngine()
        db.init_app(self.app)
        self.assertTrue(db.connection.tz_aware)

        # PyMongo defaults to tz_aware = True so we have to explicitly turn
        # it off.
        self.app.config['MONGODB_SETTINGS'] = {
            'DB': 'testing',
            'ALIAS': 'tz_aware_false',
            'TZ_AWARE': False
        }
        db = MongoEngine()
        db.init_app(self.app)
        self.assertFalse(db.connection.tz_aware)
开发者ID:871392231,项目名称:flask-mongoengine,代码行数:23,代码来源:test_basic_app.py

示例14: test_connection_missing_db

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
    def test_connection_missing_db(self):
        app = flask.Flask(__name__)
        app.config['MONGODB_SETTINGS'] = {
            'alias': 'tz_aware_true',
            'TZ_AWARE': True
        }
        app.config['TESTING'] = True
        db = MongoEngine()
        try:
            db.init_app(app)
            self.assertFalse("ValueError should've been raised")
        except ValueError:
            pass

        app.config['MONGODB_HOST'] = 'mongodb://localhost'
        app.config['TESTING'] = True
        db = MongoEngine()
        try:
            db.init_app(app)
            self.assertFalse("ValueError should've been raised")
        except ValueError:
            pass
开发者ID:corydolphin,项目名称:flask-mongoengine,代码行数:24,代码来源:test_basic_app.py

示例15: create_app

# 需要导入模块: from flask.ext.mongoengine import MongoEngine [as 别名]
# 或者: from flask.ext.mongoengine.MongoEngine import init_app [as 别名]
def create_app():
    app = Flask(__name__, static_folder='../public/', static_url_path='/public')
    app.response_class = ResponseJSON
    app.config.from_pyfile(config.FLASK_CONFIG_PATH)

    # change debug output formatter to a pretty one-liner
    format = Formatter("%(levelname)6s | %(relativeCreated)6d | %(filename)s:%(lineno)d | %(message)s")
    app.logger.handlers[0].setFormatter(format)

    # resolve paths relative to this file
    app_path = path.dirname(__file__)
    app.config.update({
        'RECORDINGS_PATH': path.realpath(app_path + '/../public/recordings/'),
        'PATH_USER_PROFILE_IMAGE': path.realpath(app_path + '/../public/profile_images/'),
        'PATH_ASSETS': path.realpath(app_path + '/../public/assets/'),
        'PATH_PUBLIC': path.realpath(app_path + '/../public/'),
    })

    # sanity checks
    if not path.isdir(app.config['RECORDINGS_PATH']):
        raise Exception("Recordings path does not exist: " + app.config['RECORDINGS_PATH'])

    if not path.isdir(app.config['PATH_USER_PROFILE_IMAGE']):
        raise Exception("User profile images path does not exist: " + app.config['PATH_USER_PROFILE_IMAGE'])

    # app.json_encoder = MongoJsonEncoder

    # setup database and session storage
    # db settings come from flask.ini
    # and same engine is used for storing sessions
    mongo = MongoEngine()
    mongo.init_app(app)
    app.session_interface = MongoEngineSessionInterface(mongo)

    # toolbar = DebugToolbarExtension(app)

    return app, mongo
开发者ID:halfvector,项目名称:quips-python,代码行数:39,代码来源:services.py


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