def authbackend_init(name): app = Flask(name) app.config.from_object(__name__ + '.ConfigClass') app.config['globalConfig'] = GlobalConfig() authinit(app) db.init_app(app) return app
def make_app(config='config.py'): app = Flask(__name__, static_folder='frontend/dist/static', template_folder='frontend/dist') app.config.from_pyfile(config) # LOGGING CONSTANTS formatter = logging.Formatter( "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s") handler = logging.handlers.RotatingFileHandler(app.config['APP_LOG_FILE'], maxBytes=1024 * 1024 * 100, backupCount=20) handler.setFormatter(formatter) handler.setLevel(app.config['APP_LOG_LEVEL']) app.logger.addHandler(handler) app.logger.setLevel(app.config['APP_LOG_LEVEL']) db.init_app(app) sess.init_app(app) from app.modules import core app.register_blueprint(core.module) return app
from flask import Flask, url_for, redirect, render_template, request from flask_login import login_required, current_user, login_user, logout_user from dashboards import dashboard_list from login_manager import login_manager, authenticate_user from db_models import User, Wine, db from dummy_data import create_dummy_user, load_wine_data app = Flask(__name__) app.secret_key = 'SuperDuperSecretSecret' app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///./app.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False with app.app_context(): db.init_app(app) db.create_all() if User.query.first() is None: create_dummy_user() if Wine.query.first() is None: load_wine_data() for app_type in dashboard_list: try: app_type.create_dash_app(app) except: traceback.print_exc() for view_func in app.view_functions: if view_func.startswith('/dashboards'): app.view_functions[view_func] = login_required(
@app.route('/list', methods=['GET']) def printlist(): """List of all the arduinos registered in the db. """ sensor_list = Sensor.query.order_by(Sensor.id.desc()).all() return render_template('list.html', lista=sensor_list) @app.route('/favicon.ico') def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon') if __name__ == '__main__': # db.create_all() db.app = app db.init_app(app) # initialize the db with app.test_request_context(): db.create_all() port = 5000 interface = '0.0.0.0' app.run(host=interface, port=port) # start the server