def __create_app(settings_override=None): """ Create a Flask application using the app factory pattern. :param settings_override: Override settings :return: Flask app """ # config app = Flask(__name__, instance_relative_config=True) app.config.from_object('config.settings') app.config.from_pyfile('settings.py', silent=True) # logger gunicorn_logger = logging.getLogger('gunicorn.error') app.logger.handlers = gunicorn_logger.handlers app.logger.setLevel(gunicorn_logger.level) if settings_override: app.config.update(settings_override) # application __middleware(app) __error_templates(app) __extensions(app) if app.debug: app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True) lessc(app).cssify('tracker/static/styles/main.less') return app
def create_app(config={}): ''' Create the flask app and setup extensions and blueprints. Returns ------- app: Flask app app with settings and blueprints loadeds. ''' app = Flask(__name__, static_folder=absolute_path('static'), template_folder=absolute_path('templates')) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + absolute_path( DATABASE_FILE) app.config['DB_NAME'] = DATABASE_FILE # Autoreload if templates change app.config['TEMPLATES_AUTO_RELOAD'] = True # flask_upload settings # app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024 # Remove Upload limit. FIX ISSUE app.config['UPLOADED_FILES_DEST'] = absolute_path('static/multimedia') app.config['UPLOADED_FILES_ALLOW'] = reduce(lambda sum, group: sum + group, SUPPORTED_MEDIA_FILES) app.config['SECRET_KEY'] = os.urandom(24) app.config.update(config) # Initiating extensions before registering blueprints Moment(app) QRcode(app) configure_uploads(app, files) login_manager.init_app(app) db.init_app(app) migrate.init_app(app, db=db) datepicker( app, local=['static/css/jquery-ui.min.css', 'static/jquery-ui.min.js']) colorpicker(app, local=['static/css/spectrum.css', 'static/spectrum.js']) fontpicker(app, local=[ 'static/jquery-ui.min.js', 'static/css/jquery-ui.min.css', 'static/webfont.js', 'static/webfont.select.js', 'static/css/webfont.select.css' ]) lessc(app) minify(app, js=True, caching_limit=3, fail_safe=True, bypass=['/touch/<int:a>', '/serial/<int:t_id>', '/display']) gTTs.init_app(app) gtranslator.init_app(app) # Register blueprints app.register_blueprint(administrate) app.register_blueprint(core) app.register_blueprint(cust_app) app.register_blueprint(manage_app) app.jinja_env.add_extension('jinja2.ext.loopcontrols') return app
def create_app(): app = Flask(__name__, static_folder=r_path('static'), template_folder=r_path('templates')) if getattr(sys, 'frozen', False): basedir = os.path.dirname(sys.executable) else: basedir = os.path.abspath(os.path.dirname(__file__)) # bootstrap = Bootstrap(app) pagedown = PageDown(app) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + r_path( 'data.sqlite') # Autoreload if templates change app.config['TEMPLATES_AUTO_RELOAD'] = True # flask_upload settings # app.config['MAX_CONTENT_LENGTH'] = 500 * 1024 * 1024 # Remove Upload limit. FIX ISSUE app.config['UPLOADED_FILES_DEST'] = r_path('static/multimedia') app.config['UPLOADED_FILES_ALLOW'] = mdal app.config['SECRET_KEY'] = os.urandom(24) # Intiating extensions before registering blueprints moment = Moment(app) qrc = QRcode(app) configure_uploads(app, files) login_manager.init_app(app) db.init_app(app) datepicker( app, local=['static/css/jquery-ui.min.css', 'static/jquery-ui.min.js']) colorpicker(app, local=['static/css/spectrum.css', 'static/spectrum.js']) fontpicker(app, local=[ 'static/jquery-ui.min.js', 'static/css/jquery-ui.min.css', 'static/webfont.js', 'static/webfont.select.js', 'static/css/webfont.select.css' ]) lessc(app) minify(app, js=True, cache=True, fail_safe=True, bypass=['/touch/<int:a>', '/serial/<int:t_id>', '/display']) gtts(app=app, route=True) gtranslator.init_app(app) # Register blueprints app.register_blueprint(administrate) app.register_blueprint(core) app.register_blueprint(cust_app) app.register_blueprint(errorsh_app) app.register_blueprint(manage_app) app.jinja_env.add_extension('jinja2.ext.loopcontrols') return app
def create_app(settings_override=None): """ Create a Flask application using the app factory pattern. :param settings_override: Override settings :return: Flask app """ app = Flask(__name__, instance_relative_config=True) app.config.from_object('config.settings') app.config.from_pyfile('settings.py', silent=True) if settings_override: app.config.update(settings_override) middleware(app) error_templates(app) app.register_blueprint(page) extensions(app) if app.debug: app.wsgi_app = DebuggedApplication(app.wsgi_app, evalex=True) lessc(app).cssify('cmdi/static/styles/main.less') return app
from flask import Flask, render_template from flask_less import lessc from atexit import register from os import remove, rmdir, mkdir, path app = Flask(__name__, template_folder='.') lessc(app=app) def cleanUp(): try: remove('index.html') remove('static/main.less') remove('static/main.css') rmdir('static') except Exception: pass register(cleanUp) @app.route('/') def root(): if not path.isdir('static'): mkdir('static') with open('static/main.less', 'w+') as file: file.write( "h1 { color: white; } body { color: red; background-color: darken(red, 30%) }" ) with open('index.html', 'w+') as file: