本文整理汇总了Python中extensions.db.init_app函数的典型用法代码示例。如果您正苦于以下问题:Python init_app函数的具体用法?Python init_app怎么用?Python init_app使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了init_app函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: register_extensions
def register_extensions(app):
# Flask-SQLAlchemy
db.init_app(app)
db.app = app
# Flask-Redis
# rd.init_app(app)
# Flask-Migrate
# migrate.init_app(app, db)
# Flask-Mail
mail.init_app(app)
# Flask-Cache
# cache.init_app(app)
# Flask-Login
from models import AnonymousUser
login_manager.session_protection = 'basic'
login_manager.login_view = 'blog.articles'
login_manager.login_message = 'please login first~'
login_manager.anonymous_user = AnonymousUser
login_manager.init_app(app)
开发者ID:cymoo,项目名称:very-simple,代码行数:26,代码来源:main.py
示例2: configure_extensions
def configure_extensions(app):
# I18N
babel.init_app(app)
# Database
db.init_app(app)
# CouchDB
couchdbmanager.setup(app)
couchdbmanager.sync(app)
# Login
login_manager.init_app(app)
login_manager.login_view = "authentification.login"
# Roles
principal.init_app(app)
# Mail
mail.init_app(app)
# Plugins list global
plugin_manager.init_plugin_manager(app.root_path + "/plugins", app)
plugin_manager.activate_plugins()
plugin_manager.setup_plugins()
开发者ID:sboily,项目名称:xivo-unified,代码行数:25,代码来源:__init__.py
示例3: configure_extensions
def configure_extensions(app):
from extensions import cache, db, mail, Login
# initialize mail
mail = mail.init_app(app)
# initialize cache
cache = cache.init_app(app)
# initialize database
db.init_app(app)
app.logger.info("Database initialized.")
db.app = app
db.metadata.bind = db.get_engine(app)
db.metadata.reflect()
app.logger.info("Database tables reflected.")
from models import User
db.create_all(bind=['users'])
# login
Login.manager.setup_app(app)
@Login.manager.user_loader
def load_user(userid):
return User.query.get(userid)
@Login.manager.token_loader
def load_token(token):
return User.query.filter(User.passkey == token).first()
开发者ID:feltnerm,项目名称:busby,代码行数:29,代码来源:app.py
示例4: create_app
def create_app(settings_folder):
# App
app = Flask(__name__)
app.config.from_pyfile(os.path.join("..", "settings", "common.py"), silent=False)
# os.path.join(settings_folder, 'common.py'), silent=False)
app.config.from_pyfile(os.path.join(settings_folder, "local_settings.py"), silent=False)
CORS(app, resources={r"*": {"origins": "*"}})
# DB
db.init_app(app)
# Signer/Verifier
sv.config(pub_key_path=os.path.join(settings_folder, "keypub"))
# API
api.init_app(app)
app.register_blueprint(apidoc.apidoc)
api.app = app
# Mail
api.mail = Mail(app)
api.urltoken = URLSafeTimedSerializer(app.config["SECRET_KEY"])
return app
开发者ID:okfn-brasil,项目名称:tagarela,代码行数:25,代码来源:app.py
示例5: init_extensions
def init_extensions(app):
db.init_app(app)
db.app = app
db.metadata.naming_convention = {
"ix": 'ix_%(column_0_label)s',
"uq": "uq_%(table_name)s_%(column_0_name)s",
"ck": "ck_%(table_name)s_%(column_0_name)s",
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
"pk": "pk_%(table_name)s"
}
# set constraint naming convention to sensible default, per
# http://docs.sqlalchemy.org/en/rel_0_9/core/constraints.html#configuring-constraint-naming-conventions
assets.init_app(app)
assets.app = app
babel.init_app(app)
cache.init_app(app)
csrf.init_app(app)
mail.init_app(app)
login_manager.init_app(app)
rq.init_app(app)
app.rq = rq
store.init_app(app)
rest.init_app(app, flask_sqlalchemy_db=db,
preprocessors=restless_preprocessors)
rest.app = app
limiter.init_app(app)
for handler in app.logger.handlers:
limiter.logger.addHandler(handler)
if app.config.get('DEBUG'):
from flask_debugtoolbar import DebugToolbarExtension
DebugToolbarExtension(app)
app.debug = True
开发者ID:18mr,项目名称:call-congress,代码行数:35,代码来源:app.py
示例6: create_app
def create_app(settings_overrides=None):
app = Flask(__name__)
# Using Cross-origin resource sharing to allow
# the ajax call from another domain since
# SimpleHTTPServer runs on port 8000 and this
# application runs on port 5000
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
configure_settings(app, settings_overrides)
# Initialise database
db.init_app(app)
configure_blueprints(app)
with app.app_context():
db.create_all()
# Initialising the data in the database
# this should not be needed in a real system
# since the data would be fed in as a result or
# real events taking place.
# However for the sake of this task we need data to work with
# so will keeo this here.
if not Shop.query.count():
load_shops('shops.csv')
if not Product.query.count():
load_products('products.csv')
if not Tag.query.count():
load_tags('tags.csv')
if not Tagging.query.count():
load_taggings('taggings.csv')
return app
开发者ID:tsheasha,项目名称:spatial-search,代码行数:34,代码来源:app.py
示例7: create_app
def create_app(settings_folder):
# App
app = Flask(__name__)
app.config.from_pyfile(
os.path.join('..', 'settings', 'common.py'), silent=False)
# os.path.join(settings_folder, 'common.py'), silent=False)
app.config.from_pyfile(
os.path.join(settings_folder, 'local_settings.py'), silent=False)
CORS(app, resources={r"*": {"origins": "*"}})
# DB
db.init_app(app)
# Signer/Verifier
sv.config(priv_key_path=os.path.join(settings_folder, 'key'),
priv_key_password=app.config['PRIVATE_KEY_PASSWORD'])
# API
api.init_app(app)
app.register_blueprint(apidoc.apidoc)
api.app = app
# Social
init_social_models(app)
# Mail
api.mail = Mail(app)
return app
开发者ID:okfn-brasil,项目名称:viralata,代码行数:29,代码来源:app.py
示例8: configure_extensions
def configure_extensions(app):
""" Configure app extension. """
# flask SQLAlchemy
db.init_app(app)
db.create_all(app=app)
# CSRF Protection
csrf.init_app(app)
@csrf.error_handler
def csrf_error(reason):
raise CsrfTokenError()
# mail.init_app(app)
# flask OAuthlib
oauth.init_app(app)
# Login Manger
login_manager.init_app(app)
# Interface for anonymous users
class AnonymousUserMixin(_AnonymousUserMixin):
username = 'Guest User'
firstName = ''
lastName = ''
email = ''
role = Role.GUEST
is_admin = False
login_manager.login_view = 'auth.post_login'
login_manager.session_protection = "strong"
login_manager.anonymous_user = AnonymousUserMixin
开发者ID:LuizGsa21,项目名称:blogger-backend,代码行数:33,代码来源:app.py
示例9: make_application
def make_application():
app = Flask(__name__, instance_relative_config=True)
app.config.from_pyfile("config.py")
logging.basicConfig(level=app.config["LOGGER_LEVEL"], format=app.config["LOGGER_FORMAT"])
# Setup sqlalchemy
db.init_app(app)
@app.after_request
def after_request(response):
try:
db.session.commit()
except Exception:
db.session.rollback()
abort(500)
return response
# blueprints
from views import docs
app.register_blueprint(docs, url_prefix="/docs")
# Config jinjia global variables
app.jinja_env.filters["error_class"] = filters.error_class
app.jinja_env.filters["error_text"] = filters.error_text
app.jinja_env.filters["dateformat"] = filters.dateformat
app.jinja_env.filters["empty"] = filters.empty
app.jinja_env.globals["static"] = lambda filename: url_for("static", filename=filename)
return app
开发者ID:greatghoul,项目名称:Local,代码行数:30,代码来源:main.py
示例10: create_app
def create_app(config_filename=None):
app = Flask(__name__, instance_relative_config=True)
if app.config.from_pyfile("settings.conf", silent=True):
print "Settings loaded from local instance"
if app.config.from_envvar("RSVP_CONF", silent=True):
print "Settings loaded from ENVVAR"
if app.config["DEBUG"]:
app.debug = True
log_formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
root_logger = logging.getLogger("werkzeug")
if app.config["DEBUG"]:
root_logger.setLevel(logging.DEBUG)
file_handler = logging.FileHandler("{}/{}".format(app.config["LOGDIR"], "rsvp.log"))
file_handler.setFormatter(log_formatter)
root_logger.addHandler(file_handler)
console_handler = logging.StreamHandler()
console_handler.setFormatter(log_formatter)
root_logger.addHandler(console_handler)
from extensions import db
import models
db.init_app(app)
models.create_all(app)
from views import views_bp
app.register_blueprint(views_bp)
return app
开发者ID:edwinavalos,项目名称:flask-rsvp,代码行数:28,代码来源:flask_app.py
示例11: create_app
def create_app(config=None):
"""Return a Flask application according to application factory design pattern function.
Create app object. Configure it. Initialize Flask extensions. Register Blueprints.
:type config: dict
:param config: Additional configuration that'll override default values
"""
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db' # sqlite://<nohostname>/<path>
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config.from_pyfile('secret.py', silent=True)
if config is not None:
app.config.update(config)
misaka.init_app(app)
login_manager.init_app(app)
db.init_app(app)
app.register_blueprint(login)
app.register_blueprint(static_pages)
app.register_blueprint(blog, url_prefix='/blog')
app.register_blueprint(simple_routes)
app.register_blueprint(tags_api, url_prefix='/blog')
return app
开发者ID:vug,项目名称:personalwebapp,代码行数:28,代码来源:factory.py
示例12: create_app
def create_app():
app = Flask("foo")
app.config.from_object(ConfigDev)
db.init_app(app)
register_blueprints(app)
return app
开发者ID:flaviomicheletti,项目名称:flask-collection,代码行数:8,代码来源:app.py
示例13: register_extensions
def register_extensions(app):
assets.init_app(app)
bcrypt.init_app(app)
cache.init_app(app)
db.init_app(app)
login_manager.init_app(app)
debug_toolbar.init_app(app)
migrate.init_app(app, db)
return None
开发者ID:gabeos,项目名称:docker-flask-template,代码行数:9,代码来源:app.py
示例14: register_extensions
def register_extensions(app):
db.init_app(app)
bcrypt.init_app(app)
lm.init_app(app)
lm.login_view = 'auth.login'
toolbar.init_app(app)
mail.init_app(app)
migrate.init_app(app, db)
return None
开发者ID:johnharris85,项目名称:escalante,代码行数:9,代码来源:escalante.py
示例15: create_app
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
db.init_app(app)
# Register the blueprints
from appblueprint.views import externalmodule
app.register_blueprint(externalmodule, url_prefix='/externalmodule')
return app
开发者ID:gonza-peralta,项目名称:flask-celery,代码行数:9,代码来源:factory.py
示例16: configure_extensions
def configure_extensions(app):
login_manager = LoginManager()
login_manager.init_app(app)
@login_manager.user_loader
def load_user(id):
return User.query.filter_by(id=id).first()
db.init_app(app)
bcrypt.init_app(app)
开发者ID:kelliedlynch,项目名称:novella-web,代码行数:10,代码来源:__init__.py
示例17: create_app
def create_app():
app = Flask(__name__)
app.config.from_object('utopia.settings')
db.init_app(app)
app.register_blueprint(index)
return app
开发者ID:rmmh,项目名称:utopia,代码行数:10,代码来源:app.py
示例18: register_extensions
def register_extensions(app):
cache.init_app(app)
db.init_app(app)
admin.init_app(app)
register_admin_views(admin)
user_datastore = MongoEngineUserDatastore(db, User, Role)
security = Security(app, user_datastore, confirm_register_form=ExtendedRegisterForm)
mail.init_app(app)
debug_toolbar.init_app(app)
return None
开发者ID:nikitph,项目名称:Narayana3,代码行数:11,代码来源:nyna.py
示例19: create_app
def create_app(config=None):
app = Flask(__name__)
app.config.from_object(DevConfig)
if config is not None:
app.config.from_object(config)
db.init_app(app)
register_blueprints(app)
return app
开发者ID:cmsdesigner,项目名称:lmm,代码行数:11,代码来源:app.py
示例20: create_app
def create_app():
app_init = Flask(__name__)
app_init.config.from_object('config')
db.init_app(app_init)
db.app = app_init
bootstrap.init_app(app_init)
migrate.init_app(app_init, db)
if app_init.config['DEBUG'] is True:
app_init.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
debug_toolbar.init_app(app_init)
return app_init
开发者ID:luuquangvu,项目名称:fastmonitor,代码行数:11,代码来源:app.py
注:本文中的extensions.db.init_app函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论