本文整理汇总了Python中models.db.init_app函数的典型用法代码示例。如果您正苦于以下问题:Python init_app函数的具体用法?Python init_app怎么用?Python init_app使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了init_app函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_app
def create_app(config_file):
from models import db
import models
app = Flask(__name__)
app.config.from_object(config_file)
app.url_map.default_subdomain = "media"
app.register_blueprint(media)
app.register_blueprint(api_home)
app.register_blueprint(api_1_0)
db.init_app(app)
admin = Admin(app, name='TheMetaCity Media')
admin.add_view(ModelView(models.MediaItem, db.session, 'Media Items'))
admin.add_view(ModelView(models.VideoFile, db.session, 'Video Files'))
admin.add_view(ModelView(models.VideoTrack, db.session, 'Video Tracks'))
admin.add_view(ModelView(models.Video, db.session, 'Video'))
admin.add_view(ModelView(models.AudioFile, db.session, 'Audio Files'))
admin.add_view(ModelView(models.AudioTrack, db.session, 'Audio Tracks'))
admin.add_view(ModelView(models.Audio, db.session, 'Audio'))
admin.add_view(ModelView(models.Picture, db.session, 'Pictures'))
admin.add_view(ModelView(models.Tags, db.session, 'Tags'))
admin.add_view(ModelView(models.Code, db.session, 'Code'))
admin.add_view(ModelView(models.Postcards, db.session, 'Postcards'))
admin.add_view(ModelView(models.Licence, db.session, 'Licences'))
return app
开发者ID:dougmiller,项目名称:theMetaCityMedia,代码行数:26,代码来源:__init__.py
示例2: create_app
def create_app():
app = Flask(__name__)
app.secret_key = 'super~~~~~~~~~~~~'
# url
app.register_blueprint(welcome_page)
app.register_blueprint(auth_page)
# db
if socket.gethostname() == 'lihaichuangdeMac-mini.local':
print(1)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://sctlee:[email protected]:3306/singledog'
else:
print(2)
conn_string = 'mysql+pymysql://%s:%[email protected]%s:%s/%s' % (os.getenv('MYSQL_USERNAME'), os.getenv('MYSQL_PASSWORD'),\
os.getenv('MYSQL_PORT_3306_TCP_ADDR'), os.getenv('MYSQL_PORT_3306_TCP_PORT'),\
os.getenv('MYSQL_INSTANCE_NAME'))
print(conn_string)
app.config['SQLALCHEMY_DATABASE_URI'] = conn_string
db.init_app(app)
from models import User
db.create_all(app=app)
# login manager
login_manager.init_app(app)
@app.before_request
def before_request():
g.user = current_user
return app
开发者ID:sctlee,项目名称:flask-docker,代码行数:33,代码来源:app.py
示例3: create_app
def create_app(config_file):
application = Flask(__name__)
application.config.from_pyfile(config_file)
from models import db, Task, User
from auth import auth_api, login_manager
from task_api import TaskListApi, TaskApi
from user_api import UserApi
db.init_app(application)
login_manager.init_app(application)
application.register_blueprint(auth_api, url_prefix="/api/auth")
api = Api(application, decorators=[login_required])
api.add_resource(TaskListApi, "/api/tasks", endpoint="tasks")
api.add_resource(TaskApi, "/api/tasks/<int:id>", endpoint="task")
api.add_resource(UserApi, "/api/users", endpoint="user")
# FOR DEVELOPMENT ONLY
@application.after_request
def after_request(response):
response.headers.add("Access-Control-Allow-Origin", "*")
response.headers.add("Access-Control-Allow-Headers", "Content-Type,Authorization")
response.headers.add("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE")
return response
return application
开发者ID:taurenk,项目名称:Flask-Angular-TaskList,代码行数:29,代码来源:__init__.py
示例4: create_app
def create_app(config_file):
application = Flask(__name__)
application.config.from_pyfile(config_file)
db.init_app(application)
api = Api(application)
from athlete_api import AthletesAPI, AthletesListAPI
from athlete_stats_api import StrongestAthletesAPI
from team_api import TeamsListAPI
api.add_resource(AthletesListAPI, '/api/athletes', endpoint='athletes_list')
api.add_resource(AthletesAPI, '/api/athletes/<int:id>', endpoint='athletes')
api.add_resource(StrongestAthletesAPI, '/api/athletes/stats/strongest',
endpoint='strongest_athletes')
api.add_resource(TeamsListAPI, '/api/teams', endpoint='teams_list')
@application.route('/')
def welcome():
return 'Welcome to Taurenk\'s CrossfitProject API'
@application.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Origin', '*')
response.headers.add('Access-Control-Allow-Headers', 'Content-Type')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
return response
return application
开发者ID:taurenk,项目名称:Crossfit-Project-API,代码行数:33,代码来源:__init__.py
示例5: create_app
def create_app():
application = Flask(__name__)
application.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI
# application.config['BABEL_DEFAULT_LOCALE'] = 'ru-ru'
application.config['SECRET_KEY'] = SECRET_KEY
application.permanent_session_lifetime = timedelta(minutes=30)
Triangle(application)
assets.init_app(application)
api.init_app(application)
api.application = application
db.init_app(application)
admin.init_app(application)
login_manager.init_app(application)
application.db = db
application.api = api
babel = Babel(application)
@babel.localeselector
def get_locale():
return request.accept_languages.best_match(["ru"])
init_logging(application)
return application
开发者ID:StasEvseev,项目名称:buy_api,代码行数:25,代码来源:app.py
示例6: create_app
def create_app(debug=False):
app = Flask(__name__)
app.debug = debug
app.secret_key = 'this is a secret'
app.json_encoder = Jsonifier
app.file_root = os.path.abspath(os.path.dirname(__file__))
app.before_request(before_request)
app.after_request(after_request)
app.context_processor(context_processor)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
db.init_app(app)
with app.app_context():
init_all()
app.register_blueprint(admin_app, url_prefix='/admin')
app.register_blueprint(campaign_app, url_prefix='/')
app.register_blueprint(character_app, url_prefix='/character')
app.register_blueprint(dm_app, url_prefix='/dm')
app.register_blueprint(chat_app, url_prefix='/chat')
app.register_blueprint(items_app, url_prefix='/item-type')
app.register_blueprint(knowledge_app, url_prefix='/knowledge')
return app
开发者ID:simonbw,项目名称:dndhelper,代码行数:26,代码来源:dndhelper.py
示例7: create_app
def create_app(config_name):
app.config.from_object(config[config_name])
db.init_app(app)
login_manager.init_app(app)
login_manager.session_protection = 'strong'
login_manager.login_view = 'admin.login'
if not app.debug:
import logging
from logging import FileHandler, Formatter
file_handler = FileHandler(Constant.LOG_DIR, encoding='utf8')
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(Formatter(
'[%(asctime)s] %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'))
app.logger.addHandler(file_handler)
from main import main as main_blueprint
app.register_blueprint(main_blueprint)
from admin import admin as admin_blueprint
app.register_blueprint(admin_blueprint, url_prefix='/admin')
patch_request_class(app, size=16*1024*1024) # 16MB
configure_uploads(app, resource_uploader)
return app
开发者ID:TSS2,项目名称:a,代码行数:28,代码来源:__init__.py
示例8: create_app
def create_app():
"""
Create the application and return it to the user
:return: flask.Flask application
"""
app = Flask(__name__, static_folder=None)
app.url_map.strict_slashes = False
# Load config and logging
Consul(app) # load_config expects consul to be registered
load_config(app)
logging.config.dictConfig(
app.config['SAMPLE_APPLICATION_LOGGING']
)
# Register extensions
api = Api(app)
Discoverer(app)
db.init_app(app)
api.add_resource(UnixTime, '/time')
api.add_resource(PrintArg, '/print/<string:arg>')
api.add_resource(ExampleApiUsage, '/search')
return app
开发者ID:jonnybazookatone,项目名称:adsabs-webservices-blueprint,代码行数:27,代码来源:app.py
示例9: create_app
def create_app():
"""
Create the application and return it to the user
:return: flask.Flask application
"""
app = Flask(__name__, static_folder=None)
app.url_map.strict_slashes = False
Consul(app)
load_config(app)
logging.config.dictConfig(
app.config['GRAPHICS_LOGGING']
)
api = Api(app)
api.add_resource(Graphics, '/<string:bibcode>')
db.init_app(app)
Discoverer(app)
return app
开发者ID:jonnybazookatone,项目名称:graphics_service,代码行数:25,代码来源:app.py
示例10: create_app
def create_app(config=None, environment=None):
app = Flask(__name__)
# TODO: Get this from a config file
app.config["MONGODB_SETTINGS"] = {'db': "eatdb"}
app.config[
"SECRET_KEY"] = "\x1a\xb1\x9d\x1d\xf2\x01\xa1X\xb8g\xed\x1c\xb3\x0f+s\xbce\xf6\x92\x83'\xf2\xbc\x96\xc6\x18\x03`\xc0\x0c("
app.config["IV"] = '\xe7\x9d\xc7\xbd\x12l\x88\xc7\xe9D\x93!\xa2B\xed\x91'
app.config.from_pyfile('settings.cfg', silent=True)
app.session_interface = MongoSessionInterface(**(app.config["MONGODB_SETTINGS"]))
with app.app_context():
from models import db
db.init_app(app)
login_manager = LoginManager()
@login_manager.user_loader
def load_user(id):
if id in (None, 'None'):
return None
try:
from models.user import User
return User.objects(id=id).first()
except:
return None
login_manager.init_app(app)
from views import register_routes as register_views
register_views(app)
return app
开发者ID:Lunchable,项目名称:eat,代码行数:34,代码来源:factory.py
示例11: create_app
def create_app():
from colorama import init
init()
from config import add_configs
app = add_configs(Flask(__name__))
from sqlalchemy_utils.functions import database_exists, create_database
if not database_exists(app.config.get('SQLALCHEMY_DATABASE_URI')):
create_database(app.config.get('SQLALCHEMY_DATABASE_URI'), encoding='utf8')
with app.app_context():
from models import db
db.init_app(app)
app.db = db
from models.oauth2 import oauth2_provider
oauth2_provider.init_app(app)
# import models
Migrate(app, db, directory='bin/migrations/')
mgr = Manager(app)
mgr.add_command('db', MigrateCommand)
return mgr
开发者ID:st2forget,项目名称:flask-restful,代码行数:26,代码来源:migrations.py
示例12: create_app
def create_app():
from config import add_configs
# Register configurations
application = add_configs(Flask(__name__))
with application.app_context():
# Register database (SQLAlchemy)
from models import db
db.init_app(application)
application.db = db
"""
@:type SQLAlchemy
"""
# Register OAuth2
from models.oauth2 import oauth2_provider
oauth2_provider.init_app(application)
# Register BluePrints
from controllers import add_blueprints
add_blueprints(application)
# Register Api
from controllers import add_apis
from flask_restful import Api
add_apis(Api(application))
return application
开发者ID:st2forget,项目名称:flask-restful,代码行数:28,代码来源:app.py
示例13: create_app
def create_app():
app = Flask(__name__)
load_config(app)
app.debug = app.config['DEBUG']
app.secret_key = app.config['SECRET_KEY']
# init flask extensions
db.init_app(app)
mail.init_app(app)
login_manager.init_app(app)
app.context_processor(inject_roles)
# init my modules
upload.init_app(app)
filters.init_app(app)
views.init_app(app)
# register routes
app.register_blueprint(views.bp_basic)
app.register_blueprint(views.bp_responsable)
app.register_blueprint(views.bp_activite)
app.register_blueprint(views.bp_brn)
return app
开发者ID:vddd,项目名称:rn,代码行数:26,代码来源:main.py
示例14: setUp
def setUp(self):
app = Flask("tests", static_url_path="/static")
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////tmp/test_idb.db"
db.init_app(app)
db.app = app
db.configure_mappers()
db.create_all()
开发者ID:tweetcity,项目名称:cs373-idb,代码行数:8,代码来源:tests.py
示例15: create_app
def create_app():
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///stress.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
with app.app_context():
db.create_all()
return app
开发者ID:xMrWhite,项目名称:Affektive,代码行数:8,代码来源:main.py
示例16: connect_to_db
def connect_to_db(app):
"""Connect the database to our Flask app."""
# Configure to use our PstgreSQL database
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///test'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.app = app
db.init_app(app)
开发者ID:Aisling-Dempsey,项目名称:Haven,代码行数:8,代码来源:tests.py
示例17: create_app
def create_app():
app = flask.Flask("app")
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
app.register_blueprint(api)
db.init_app(app)
with app.app_context():
db.create_all()
return app
开发者ID:chfw,项目名称:sample,代码行数:8,代码来源:application.py
示例18: create_app
def create_app():
app = Flask(__name__)
app.config.from_object('config')
Bootstrap(app)
Bower(app)
app.extensions['bootstrap']['cdns']['jquery'] = WebCDN("//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/")
db.init_app(app)
return app
开发者ID:christ2go,项目名称:supertuxaddon,代码行数:9,代码来源:supertuxaddon.py
示例19: create_app
def create_app():
api = Flask('api')
api.register_blueprint(person_blueprint)
db.init_app(api)
with api.app_context():
db.create_all()
return api
开发者ID:drimer,项目名称:example-codes,代码行数:9,代码来源:app.py
示例20: create_app
def create_app():
"""Create your application."""
app = Flask(__name__)
app.config.from_object(settings)
app.register_module(views)
db.app = app
db.init_app(app)
db.create_all()
return app
开发者ID:codeforamerica,项目名称:open_data_upload,代码行数:9,代码来源:__init__.py
注:本文中的models.db.init_app函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论