def create_app(smiley=False): """Create app. Factory for app. Parameters ---------- smiley : bool, optional Determines whether the smiley functionality should be setup. """ app = Flask(__name__) Bootstrap(app) # Serve assets from wmflabs for privacy reasons app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN() app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN() if smiley: from ..smiley import Smiley app.smiley = Smiley() else: app.smiley = None from .views import main as main_blueprint app.register_blueprint(main_blueprint) return app
def create_app(): """Create webapp. Factory for webapp. Returns ------- app : flask.app.Flask Flask app object. """ app = Flask(__name__) Bootstrap(app) # Serve assets from wmflabs for privacy reasons app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN() app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN() from .views import main as main_blueprint app.register_blueprint(main_blueprint) app.text_to_topic_q_text = load_text_to_topic_q_text() return app
def create_app(): """Create webapp. Factory for webapp. Returns ------- app : flask.app.Flask Flask app object. """ app = Flask(__name__) app.model = Model.load() Bootstrap(app) CORS(app) # Serve assets locally for privacy reasons app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN() app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN() from .views import main as main_blueprint app.register_blueprint(main_blueprint) return app
def bs_init_app(app): local = StaticCDN('bootstrap.static', rev=True) static = StaticCDN() def lwrap(cdn, primary=static): return ConditionalCDN('BOOTSTRAP_SERVE_LOCAL', primary, cdn) __version__ = '4.0.0' bootstrap_version_re = re.compile(r'(\d+\.\d+\.\d+(\-[a-z]+)?)') popper_version = '1.16.0' jquery_version = '3.4.1' fontawesome_version = '5.14.0' def get_bootstrap_version(version): return bootstrap_version_re.match(version).group(1) bootstrap_version = get_bootstrap_version(__version__) popper = lwrap( WebCDN('//cdnjs.cloudflare.com/ajax/libs/popper.js/%s/' % popper_version), local) bs = lwrap( WebCDN('//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/%s/' % bootstrap_version), local) fontawesome = lwrap( WebCDN('//cdnjs.cloudflare.com/ajax/libs/font-awesome/%s/' % fontawesome_version), local) jquery = lwrap( WebCDN('//cdnjs.cloudflare.com/ajax/libs/jquery/%s/' % jquery_version), local) app.extensions['bootstrap'] = { 'cdns': { 'local': local, 'static': static, 'popper': popper, 'bootstrap': bs, 'fontawesome': fontawesome, 'jquery': jquery, }, } # setup support for flask-nav renderers = app.extensions.setdefault('nav_renderers', {}) renderer_name = (__name__ + '.nav', 'BootstrapRenderer') renderers['bootstrap'] = renderer_name # make bootstrap the default renderer renderers[None] = renderer_name
def create_app(text_to_topic_q_text_enabled=True, third_parties_enabled=False): """Create webapp. Factory for webapp. Parameters ---------- text_to_topic_q_text_enabled : bool Determines whether the text-to-topics functionality should be enabled. The loading of the matching model takes long time and it may be convenient during development to disable the functionality [default: true]. third_parties_enabled : bool Determines whether third-party webservices can be enabled. Due to privacy reason this is disabled by default [default: false]. Returns ------- app : flask.app.Flask Flask app object. """ app = Flask(__name__) app.config['config'] = config # setting a default for client side caching app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 300 Bootstrap(app) # Serve assets from wmflabs for privacy reasons app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN() app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN() from .views import main as main_blueprint app.register_blueprint(main_blueprint) app.text_to_topic_q_text_enabled = text_to_topic_q_text_enabled if text_to_topic_q_text_enabled: app.text_to_topic_q_text = load_text_to_topic_q_text() app.third_parties_enabled = third_parties_enabled return app
def create_app(config_class=Config): app = Flask(__name__) app.config.from_object(config_class) db.init_app(app) with app.app_context(): if db.engine.url.drivername == 'sqlite': migrate.init_app(app, db, render_as_batch=True) else: migrate.init_app(app, db) bootstrap.init_app(app) app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN() moment.init_app(app) # Blueprint registration from metabolite_database.errors import bp as errors_bp # noqa: E402,F401 app.register_blueprint(errors_bp) from metabolite_database.main import bp as main_bp # noqa: E402,F401 app.register_blueprint(main_bp) from metabolite_database.auth import bp as auth_bp # noqa: E402,F401 app.register_blueprint(auth_bp) if not app.debug and not app.testing: if app.config['MAIL_SERVER']: auth = None if (app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']): auth = (app.config['MAIL_USERNAME'], app.config['MAIL_PASSWORD']) secure = None if app.config['MAIL_USE_TLS']: secure = () mail_handler = SMTPHandler( mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']), fromaddr='no-reply@' + app.config['MAIL_SERVER'], toaddrs=app.config['ADMINS'], subject='Microblog Failure', credentials=auth, secure=secure) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler) if not os.path.exists('logs'): os.mkdir('logs') file_handler = RotatingFileHandler('logs/metabolite_database.log', maxBytes=10240, backupCount=10) file_handler.setFormatter( logging.Formatter('%(asctime)s %(levelname)s: ' '%(message)s [in %(pathname)s:%(lineno)d]')) file_handler.setLevel(logging.INFO) app.logger.addHandler(file_handler) app.logger.setLevel(logging.INFO) app.logger.info('Metabolite Database startup') return app
def create_app(text_to_topic_q_text_enabled=True, third_parties_enabled=False): """Create webapp. Factory for webapp. Parameters ---------- text_to_topic_q_text_enabled : bool Determines whether the text-to-topics functionality should be enabled. The loading of the matching model takes long time and it may be convenient during development to disable the functionality [default: true]. third_parties_enabled : bool Determines whether third-party webservices can be enabled. Due to privacy reason this is disabled by default [default: false]. Returns ------- app : flask.app.Flask Flask app object. """ app = Flask(__name__) Bootstrap(app) # Serve assets from wmflabs for privacy reasons app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN() app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN() from .views import main as main_blueprint from .views import page_not_found app.register_blueprint(main_blueprint) app.register_error_handler(404, page_not_found) app.text_to_topic_q_text_enabled = text_to_topic_q_text_enabled if text_to_topic_q_text_enabled: app.text_to_topic_q_text = TextToTopicQText() app.third_parties_enabled = third_parties_enabled return app
def create_app(config_filename): app = Flask(__name__) app.config.from_object(config_filename) app.logger.setLevel(app.config["LOG_LEVEL"]) bootstrap.init_app(app) app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN() db.init_app(app) ma.init_app(app) misaka.init_app(app) security.init_app(app, user_datastore) @app.login_manager.unauthorized_handler def abort_401(): return abort(401) return app
def create_app(mode='default'): app = Flask(__name__) con = config[mode] app.config.from_object(con) con.init_app(app) db.init_app(app) bootstrap.init_app(app) login_manager.init_app(app) misaka.init_app(app) moment.init_app(app) csrf.init_app(app) app.jinja_env.add_extension('jinja2.ext.loopcontrols') # bootstrap使用本地文件 from flask_bootstrap import StaticCDN cdns = app.extensions['bootstrap']['cdns'] cdns['bootstrap'] = StaticCDN('static') from app.views.main import main as main_blueprint app.register_blueprint(main_blueprint) from app.views.blog import blog as blog_blueprint app.register_blueprint(blog_blueprint, url_prefix='/blog') from app.views.todo import todo as todo_blueprint app.register_blueprint(todo_blueprint, url_prefix='/todo') from app.ajaxs.todo import ajax_todo as ajax_todo_blueprint app.register_blueprint(ajax_todo_blueprint, url_prefix='/ajax-todo') from app.views.admin import admin as admin_blueprint app.register_blueprint(admin_blueprint, url_prefix='/admin') from app.ajaxs.admin import ajax_admin as ajax_admin_blueprint app.register_blueprint(ajax_admin_blueprint, url_prefix='/ajax-admin') return app
from flask import Flask from config import Config from flask_bootstrap import Bootstrap from flask_silk import Silk from app.errors import bp as errors_bp app = Flask(__name__) app.config.from_object(Config) app.register_blueprint(errors_bp) bootstrap = Bootstrap(app) silk = Silk(app) from flask_bootstrap import StaticCDN app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN() from app import routes
from flask import Blueprint from wtforms.validators import ValidationError logger = logging.getLogger(__name__) CODEMIRROR_VERSION = '5.0.0' CDN_PREFIX = 'cdn.bootcss.com' MARKED_VERSION = '0.3.3' PRETTIFY_VERSION = '188.0.0' editormd_object_name = 'editor' default_editor_id = 'editor1' from flask_bootstrap import WebCDN, StaticCDN local = StaticCDN('editormd.static') def get_local_resource(filename): return local.get_resource_url(filename) def create_webcdn(rep_name, version): return WebCDN('//{cdn_prefix}/{rep_name}/{version}/'.format( cdn_prefix=CDN_PREFIX, rep_name=rep_name, version=version)) codemirror_webcdn = create_webcdn('codemirror', CODEMIRROR_VERSION) marked_webcdn = create_webcdn('marked', MARKED_VERSION) prettify_webcdn = create_webcdn('prettify', PRETTIFY_VERSION)
def register_plugins(app: Flask) -> Manager: "Register all the plugins to Haldis" # pylint: disable=W0612 # Register Airbrake and enable the logrotation if not app.debug: timedFileHandler = TimedRotatingFileHandler( app.config["LOGFILE"], when="midnight", backupCount=100 ) timedFileHandler.setLevel(logging.DEBUG) loglogger = logging.getLogger("werkzeug") loglogger.setLevel(logging.DEBUG) loglogger.addHandler(timedFileHandler) app.logger.addHandler(timedFileHandler) airbrakelogger = logging.getLogger("airbrake") # Airbrake airbrake = Airbrake(project_id=app.config["AIRBRAKE_ID"], api_key=app.config["AIRBRAKE_KEY"]) # ugly hack to make this work for out errbit airbrake._api_url = "http://errbit.awesomepeople.tv/api/v3/projects/{}/notices".format( # pylint: disable=W0212 airbrake.project_id ) airbrakelogger.addHandler(AirbrakeHandler(airbrake=airbrake)) app.logger.addHandler(AirbrakeHandler(airbrake=airbrake)) # Initialize SQLAlchemy db.init_app(app) # Initialize Flask-Migrate migrate = Migrate(app, db) app_manager = Manager(app) app_manager.add_command("db", MigrateCommand) app_manager.add_command("runserver", Server(port=8000)) # Add admin interface init_admin(app, db) # Init login manager login_manager = LoginManager() login_manager.init_app(app) login_manager.anonymous_user = AnonymouseUser init_login(app) # Add oauth zeus = init_oauth(app) app.zeus = zeus # Load the bootstrap local cdn Bootstrap(app) app.config["BOOTSTRAP_SERVE_LOCAL"] = True # use our own bootstrap theme app.extensions["bootstrap"]["cdns"]["bootstrap"] = StaticCDN() # Load the flask debug toolbar toolbar = DebugToolbarExtension(app) # Make cookies more secure app.config.update( SESSION_COOKIE_HTTPONLY=True, SESSION_COOKIE_SAMESITE='Lax', ) if not app.debug: app.config.update(SESSION_COOKIE_SECURE=True) return app_manager
"""app.""" from __future__ import absolute_import, division, print_function from flask import Flask from flask_bootstrap import Bootstrap, StaticCDN app = Flask(__name__) Bootstrap(app) # Serve assets from wmflabs for privacy reasons app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN() app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN( static_endpoint='serve_bootstrap_custom') from . import views
def confinit(): app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN() app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN() app.jinja_env.add_extension('jinja2.ext.do') slib.config.sslverify = app.config['CUSTOM']['verifyssl'] slib.config.apihost = app.config['CUSTOM']['apiurl']
ERROR = RUTA + "error.log" ARC_CSV = RUTA + "csv/archivo.csv" USER_CLAVE = RUTA + "csv/usuario_clave.csv" TEMP = "csv/resultados/" # App.config: app.config[ "SECRET_KEY"] = "UnaClaveSecreta" # Clave random para formularios de Flask-WTF. app.config[ "BOOTSTRAP_SERVE_LOCAL"] = True # Para activar versión local de Bootstrap. app.config[ "BOOTSTRAP_QUERYSTRING_REVVING"] = False # Para quitar el "?bootstrap=..." cuando se # buscan los archivos de bootstrap locales. # App.extensions: app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN( ) # Para poder usar archivo jQuery local. # Funciones: @app.route("/login", methods=["GET", "POST"]) @app.route("/index", methods=["GET", "POST"]) @app.route("/", methods=["GET", "POST"]) def inicio(): """ Función que lleva a inicio.html o usuario.html según condiciones. """ # Si existe algún 'user' en sesión: if session.get("user"): return redirect(url_for("usuario")) # En caso de no haber usuario logueado, se prosigue: else:
app = Flask(__name__) app.config.from_object(Config) db = SQLAlchemy(app, metadata=MetaData(naming_convention=naming_convention)) migrate = Migrate(app, db) login = LoginManager(app) login.login_view = 'login' bootstrap = Bootstrap(app) markdown = Misaka(app, tables=True, fenced_code=True, escape=True) moment = Moment(app) # override ConditionalCDN with StaticCDN if local serve is wanted # reason: using the usual local cdn results in a 404 for bootstrap.min.css.map on every page # TODO how to do this correctly? if app.config["BOOTSTRAP_SERVE_LOCAL"]: app.extensions['bootstrap']['cdns']['bootstrap'] = StaticCDN( static_endpoint='static_files') app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN( static_endpoint='static_files') from app.user import bp as user_bp app.register_blueprint(user_bp, url_prefix="/user") from app.map import bp as map_bp app.register_blueprint(map_bp, url_prefix="/map") from app.character import bp as character_bp app.register_blueprint(character_bp, url_prefix="/character") from app.party import bp as party_bp app.register_blueprint(party_bp, url_prefix="/party")