本文整理汇总了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
示例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
示例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
示例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
示例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)
示例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)
示例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
示例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)
示例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
示例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)
示例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)
示例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)
示例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)
示例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
示例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