def setUpClass(cls): # Make sure database exists app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' app.config['DEBUG'] = False app.config['PROPAGATE_EXCEPTIONS'] = True with app.app_context(): db.init_app(app)
def create_app(): app = Flask(__name__) app.config.from_object('settings') # Creating the mail object to manage emails in flask mail.init_app(app) # initializing the database lazily db.init_app(app) # initializing gravatars gravatar = Gravatar(app, size=100, rating='g', default='retro', force_default=False, force_lower=False, use_ssl=False, base_url=None) # registering the different modules in the application app.register_blueprint(blogs_blueprint,url_prefix='/blogs') app.register_blueprint(main_blueprint,url_prefix='/') app.register_blueprint(resources_blueprint,url_prefix='/resources') app.register_blueprint(users_blueprint,url_prefix='/users') # initializing the login manager lazily login_manager.init_app(app) return app
def setUp(self): app.config['SQLALCHEMY_DATABASE_URI'] = BaseTest.SQLALCHEMY_DATABASE_URI with app.app_context(): db.init_app(app) db.create_all() self.app = app.test_client() self.app_context = app.app_context
def configure(self, binder): # We configure the DB here, explicitly, as Flask-SQLAlchemy requires # the DB to be configured before request handlers are called. with self.app.app_context(): db.init_app(self.app) Base.metadata.create_all(db.engine) binder.bind(SQLAlchemy, to=db, scope=singleton)
def init_app(application): from resources import api from assets import assets from applications.security.auth import login_manager from security import security application.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI application.config['SECURITY_TOKEN_AUTHENTICATION_HEADER'] = ( "AUTHORIZATION") application.config['SECURITY_REMEMBER_SALT'] = "SALT123123123" application.config['SQLALCHEMY_ECHO'] = True 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) login_manager.init_app(application) security.init_app(application) application.db = db application.api = api if IS_PROD: init_logging(application) return application
def __init__(self, *args, **kwargs): super(Application, self).__init__(__name__) self.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True self.config['DEBUG'] = True # self.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' self.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db' db.init_app(self) self.register_blueprint(api) self.register_blueprint(user) self.register_blueprint(others) assets = Environment(self) assets.load_path = [ os.path.join(os.path.dirname(__file__), 'bower_components'), os.path.join(os.path.dirname(__file__), 'static/js'), # os.path.join(os.path.dirname(__file__), 'bower_components'), ] assets.register( 'js_all', Bundle( '**/**.min.js', 'js/**.min.js', output='js_all.js' ) )
def create_app(): app = Flask(__name__) app.config.from_object('_config') app.debug=True db.init_app(app) app.register_blueprint(notifier, url_prefix='') csrf.init_app(app) return app
def setUp(self): # Make sure database exists app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' with app.app_context(): db.init_app(app) db.create_all() # Get a test client self.app = app.test_client() self.app_context = app.app_context
def init(app): # --> Extension setup db.init_app(app) admin.init_app(app) modules["migrate"] = Migrate(app, db) modules["user_datastore"] = SQLAlchemyUserDatastore(db, User, Role) modules["security"] = Security(app, modules["user_datastore"], confirm_register_form=MyRegisterForm) # --> Register blueprints from modules.play.play import play app.register_blueprint(play, url_prefix='/play') from modules.api.core import api_core app.register_blueprint(api_core, url_prefix='/kcsapi') # Declare API v1 blueprints. from modules.api.v1.user import api_user from modules.api.v1.actions import api_actions app.register_blueprint(api_user, url_prefix='/kcsapi') app.register_blueprint(api_actions, url_prefix='/kcsapi') # Declare API v2 blueprints. from modules.api.v2.AdmiralAPI import AdmiralAPIv2 from modules.api.v2.DockAPI import DockAPIv2 app.register_blueprint(AdmiralAPIv2, url_prefix='/api/v2/admiral') app.register_blueprint(DockAPIv2, url_prefix='/api/v2/docks') from modules.resources import resources app.register_blueprint(resources, url_prefix='/kcs') # --> Base application routes @app.route('/') def index(): return render_template('index.html') @app.route('/kcs/<path:path>') def kcs(path): return send_from_directory('kcs', path) # --> Signals @user_logged_in.connect_via(app) def u_logged_in(sender, user): """ Regenerate the API token every login. """ user.api_token = generate_api_token()
def create_app(): """ creats a flask app with configs and connect db """ app = Flask(__name__) app.config.from_object('config') app.jinja_env.add_extension('jinja2.ext.loopcontrols') app.jinja_env.globals.update(get_score_color=util.get_score_color) app.jinja_env.globals.update(score_prediction=util.score_prediction) db.init_app(app) with app.app_context(): db.create_all() return app
def create_app(config='local'): app = Flask(__name__) app.config.from_object('project.settings.{}'.format(config)) # db from db import db db.init_app(app) # auth blueprint from auth import blueprint as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix="/auth") return app
def create_app(config_filename=None): app = Flask(__name__) app.config.from_pyfile(config_filename or 'config.py') from db import db db.init_app(app) db.app = app db.create_all() from views import dashboard app.register_blueprint(dashboard) return app
def create_app(config): # init our app app = Flask(__name__) app.secret_key = 'djfjsdkjXXS7979dfdfd' # load config values from the config file app.config.from_object(config) # init sqlalchemy db instance db.init_app(app) db.app = app # register blueprints app.register_blueprint(api) configure_logging(app) configure_errorhandlers(app) # configure_cors(app) # all set; return app object # app.system = System() return app
def create_app(config_object=None): app = Flask(__name__) app.config.from_object(config_object) from db import db as _db _db.init_app(app) # oauth init from oauth import oauth oauth.init_app(app) # register uuid converter from flask.ext.uuid import FlaskUUID FlaskUUID(app) # register error handlers import errors errors.init_error_handlers(app) # register loggers import loggers if app.debug is False: loggers.init_app(app) import login login.init_oauth_providers(app) # register blueprints from oauth.views import oauth_bp from login.views import login_bp from review.views import review_bp from user.views import user_bp from client.views import client_bp app.register_blueprint(oauth_bp, url_prefix='/oauth') app.register_blueprint(login_bp, url_prefix='/login') app.register_blueprint(review_bp, url_prefix='/review') app.register_blueprint(user_bp, url_prefix='/user') app.register_blueprint(client_bp, url_prefix='/client') return app
def create_app(app): #config app.config.from_object(os.environ['APP_SETTINGS']) #models db.init_app(app) ma.init_app(app) with app.app_context(): from models.book import Book from models.author import Author from models.rating import Rating from models.category import Category from models.user import User from models.log import ReadingLog db.create_all() db.session.commit() #create endpoints app.register_blueprint(endpoints)
def config_sqlalchemy(app): db.init_app(app) db.app = app
def create_app(): app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///./test.db' db.init_app(app) return app
api.add_resource(Store, "/store/<string:name>") api.add_resource(StoreList, "/stores") api.add_resource(Item, "/item/<string:name>") api.add_resource(ItemList, "/items") api.add_resource(UserRegister, "/register") api.add_resource(User, "/user/<int:user_id>") api.add_resource(UserLogin, "/login") api.add_resource(TokenRefresh, "/refresh") api.add_resource(UserLogout, "/logout") api.add_resource(Order, '/order') api.add_resource(OrderList, '/orders') api.add_resource(OrderListForUser, '/order/user/<int:user_id>') api.add_resource(Cart, '/cart/<int:user_id>', '/cart/add') api.add_resource(CartList, '/carts') api.add_resource(OrderItemsList, '/order/items/<int:order_id>') api.add_resource(MakePaymentForOrder, '/makePayment/<int:order_id>') if __name__ == "__main__": db.init_app(app) ma.init_app(app) if app.config['DEBUG']: @app.before_first_request def create_tables(): db.create_all() app.run(port=5000, debug=True)
app.config['DEBUG'] = True app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_URL', 'sqlite:///data.db') SQLALCHEMY_TRACK_MODIFICATIONS = False app.secret_key = '12345' api = Api(app) jwt = JWT(app, authenticate, identity) # /auth api.add_resource(Store, '/store/<string:name>') api.add_resource(Item, '/item/<string:name>') api.add_resource(ItemList, '/items') api.add_resource(StoreList, '/stores') api.add_resource(UserRegister, '/register') @app.errorhandler(JWTError) def auth_error_handler(err): return jsonify({'message': 'Could not authorize. Did you include a valid Authorization Header?'}), 401 if __name__ == '__main__': from db import db db.init_app(app) if app.config['DEBUG']: @app.before_first_request def create_tables(): db.create_all() app.run(port=5000)
def setUpClass(cls): app.config['SQLALCHEMY_DATABASE_URI'] = BaseTest.SQLALCHEMY_DATABASE_URI app.config['DEBUG'] = False with app.app_context(): db.init_app(app)
def setUpClass(cls): app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' with app.app_context(): db.init_app(app)
from resources.user import UserRegister, User, UserLogin from resources.property import Properties, Property from db import db app = Flask(__name__) #config DataBase app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///data.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['PROPAGATE_EXCEPTIONS'] = True app.secret_key = 'dwellingly' #Replace with Random Hash #allow cross-origin (CORS) CORS(app) api = Api(app) db.init_app(app) #need to solve this @app.before_first_request def create_tables(): db.create_all() jwt = JWTManager(app) # /authorization @jwt.user_claims_loader #check if user role == admin def role_loader(identity): #idenity = user.id in JWT user = UserModel.find_by_id(identity) if user.role == 'admin':