def client(): from mysite import create_app app = create_app(config_file=CONFIG_FILE) with app.app_context(): from mysite import db db.create_all() app.config['TESTING'] = True with app.test_client() as c: yield c
from mysite import db, create_app db.create_all(app=create_app())
import os from flask_script import Manager, Server from flask_script.commands import ShowUrls from flask_migrate import Migrate, MigrateCommand from mysite.extensions import db from mysite import create_app env = os.environ.get('APP_ENV', 'dev') app = create_app('mysite.config.%sConfig' % env.capitalize()) migrate = Migrate(app, db) manager = Manager(app) manager.add_command("server", Server()) manager.add_command("show-url", ShowUrls()) manager.add_command("db", MigrateCommand) @manager.shell def make_shell_context(): return dict( app=app, db=db ) @manager.command def setup_db(): db.create_all() if __name__ == "__main__": manager.run()
import os from flask_script import Manager from mysite import create_app, celery here = os.path.abspath(os.path.dirname(__file__)) config_file = os.path.join(here, 'config/config.py') app = create_app(config_file) manager = Manager(app) if __name__ == '__main__': manager.run()
from mysite import create_app app = create_app("mysite.config.ProdConfig")
from mysite import create_app app = create_app() app.run(debug=True)
def create_app(self): return create_app(self)
from gevent.wsgi import WSGIServer from mysite import create_app app = create_app('mysite.config.ProdConfig') server = WSGIServer(('', 80), app) server.serve_forever()
# -*- coding:utf-8 -*- from flask import Flask, current_app from flaskext.script import Server, Shell, Manager, Command, prompt_bool from mysite import create_app from mysite.extensions import db from mysite.models.model import User manager = Manager(create_app('config.cfg')) manager.add_command("runserver", Server('0.0.0.0',port=8080)) def _make_context(): return dict(db=db) manager.add_command("shell", Shell(make_context=_make_context)) @manager.command def createall(): "Creates database tables" db.create_all() @manager.command def dropall(): "Drops all database tables" if prompt_bool("Are you sure ? You will lose all your data !"): db.drop_all() if __name__ == "__main__": manager.run()