def create_app(): app = Flask(__name__) load_config(app) app.debug = app.config['DEBUG'] app.secret_key = app.config['SECRET_KEY'] # init flask extensions db.init_app(app) mail.init_app(app) login_manager.init_app(app) app.context_processor(inject_roles) # init my modules upload.init_app(app) filters.init_app(app) views.init_app(app) # register routes app.register_blueprint(views.bp_basic) app.register_blueprint(views.bp_responsable) app.register_blueprint(views.bp_activite) app.register_blueprint(views.bp_brn) return app
def init(configfile): app.config.from_pyfile('openmoves.cfg.default', silent=False) if configfile: if not os.path.exists(configfile): with open(configfile, 'w') as f: initialize_config(f) print("created %s" % configfile) app.config.from_pyfile(configfile, silent=False) assert app.config['SECRET_KEY'] SESSION_VERSION = 1 app.config['SECRET_KEY'] = "%s-%d" % (app.config['SECRET_KEY'], SESSION_VERSION) assert 'SQLALCHEMY_TRACK_MODIFICATIONS' not in app.config app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app) with app.app_context(): if db.engine.name == 'sqlite': db.create_all() Bootstrap(app) app_bcrypt.init_app(app) login_manager.init_app(app) login_manager.login_view = "login" return 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 create_app(config="config.ini"): app = Flask(__name__, static_url_path='/static') app.config.update(MONGODB_SETTINGS={'DB': 'testapp'}, TESTING=True, SECRET_KEY='flask+mongoengine=<3') # Define the WSGI application object db.init_app(app) login_manager.init_app(app) principals.init_app(app) # csrf protection csrf = CsrfProtect() csrf.init_app(app) # Register blueprint(s) from modules.inventory import inventory as inventory_blueprint app.register_blueprint(inventory_blueprint, url_prefix='/inventory') from modules.user import user as user_blueprint app.register_blueprint(user_blueprint, url_prefix='/user') from login import auth as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') @app.route("/", methods=['GET']) @login_required @user.require(http_exception=403) def index(): return render_template("index.html", menu=principal_menu()) # Sample HTTP error handling @app.errorhandler(404) def not_found(error): return render_template('404.html'), 404 @app.before_request def make_session_permanent(): session.permanent = True app.permanent_session_lifetime = timedelta(minutes=5) session.modified = True @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): needs = [] if identity.id in ('viewer', 'editor', 'admin'): needs.append(to_view) if identity.id in ('editor', 'admin'): needs.append(be_editor) if identity.id == 'admin': needs.append(be_admin) for n in needs: identity.provides.add(n) # If the authenticated identity is : # - 'the_only user' she can sign in # - "the_only_editor" she can sign in and edit # - "the_only_admin" she can sign in , edit and administrate return app
def create_app(config=cfg.current_config): app = Flask(__name__, static_folder=config.IMAGE_DIR) app.config.from_object(config) db.app = app db.init_app(app) Migrate(app, db) admin.init_app(app) login_manager.init_app(app) app.register_blueprint(webhook_bp, url_prefix='/webhook') app.register_blueprint(index_bp, url_prefix='/') app.before_first_request(init_bot) return app
def initialize_extensions(app): sqldb.init_app(app) login_manager.init_app(app) mail_api.init_app(app) bcrypt.init_app(app) debug_toolbar.init_app(app) jsglue.init_app(app) configure_uploads(app, file) csrf.init_app(app) configure_admin(app) security.init_app(app, user_datastore) # scheduler.init_app(app) # scheduler.start() # app.extensions['scheduler'] = scheduler return app
def create_app(): app = Flask(__name__, instance_relative_config=True) app.config.from_object('config') app.config.from_pyfile('config.py') db.init_app(app) login_manager.init_app(app) with app.app_context(): db.create_all() app.register_blueprint(bt_pages) app.register_blueprint(bt_admin, url_prefix='/admin') app.register_blueprint(bt_user, url_prefix='/user') return app
def create_app(test_config=None): app = Flask(__name__, instance_relative_config=True) Debug(app) # Front-end blueprint architecture of the app. Material(app) app.register_blueprint(blueprint) APP_SECRET_KEY = os.urandom(32) app.config.from_mapping( SECRET_KEY=APP_SECRET_KEY, DATABASE=os.path.join(app.instance_path, 'app.sqlite'), FLASK_DEBUG_DISABLE_STRICT='True', ) app.debug = True if test_config is None: # load the instance config, if it exists, when not testing app.config.from_pyfile('config.py', silent=True) else: # load the test config if passed in app.config.from_mapping(test_config) # ensure the instance folder exists try: os.makedirs(app.instance_path) except OSError: pass #Database managment with app.app_context(): db.init_app(app) login_manager.init_app(app) login_manager.login_view = 'blueprint.login' return app
from flask_login import login_required from flask_login import current_user from flask_login import login_user, logout_user from login import login_manager from models import db from models import OAuthToken, User from providers import oauth_providers, oauth_response_keys from services import socketio app = Flask(__name__) app.config.from_object('settings.DevelopmentConfig') db.init_app(app) socketio.init_app(app) login_manager.init_app(app) @app.route('/') def index(): return render_template('index.html') @app.route('/auth/<provider>') def auth(provider): if provider in oauth_providers: callback = url_for('authorized', provider=provider, next=request.args.get('next') or request.referrer or None, _external=True) return oauth_providers[provider].authorize(callback=callback) else: return abort(404)
import os from flask.ext.admin import Admin from flask.ext import restful from pub_app import app from models import db from views import UserView, PubTypeView, PubView, PubFile from login import login_manager, login, logout from restfuls import (UserInfo, UserLogin, UserRegister, PubGetType, PubListDetail, PubDetail, UserCollect, PubCollect, PubPictureDetail, PubSearch, GetPubType, GetProvince, GetCity, GetCounty, UserMessage) # 用户登陆管理 login_manager.init_app(app) app.add_url_rule('/login', 'login', login) app.add_url_rule('/logout', 'logout', logout) # 后台管理系统路径管理 admin = Admin(name=u'冒冒') admin.init_app(app) admin.add_view(UserView(db, name=u'用户')) admin.add_view(PubTypeView(db, name=u'酒吧类型', category=u'酒吧')) admin.add_view(PubView(db, name=u'酒吧详情', category=u'酒吧')) ### 文件管理 path = os.path.join(os.path.dirname(__file__), 'static') admin.add_view(PubFile(path, '/static/', name='文件'))
def create_app(config="config.ini"): app = Flask(__name__, static_url_path='/static') app.config.from_object(__name__) if os.path.exists(config): app.config.from_pyfile(config) else: print("The app does not have a config.ini file") # Define the WSGI application object db.init_app(app) # csrf protection login_manager.init_app(app) principals.init_app(app) csrf = CsrfProtect() csrf.init_app(app) # Register blueprint(s) from modules.inventory import inventory as inventory_blueprint app.register_blueprint(inventory_blueprint, url_prefix='/inventory') from modules.user import user as user_blueprint app.register_blueprint(user_blueprint, url_prefix='/user') from login import auth as auth_blueprint app.register_blueprint(auth_blueprint, url_prefix='/auth') @app.route("/", methods=['GET']) @login_required @user.require(http_exception=403) def index(): return render_template("index.html", menu=principal_menu()) # Sample HTTP error handling @app.errorhandler(404) def not_found(error): return render_template('404.html'), 404 # Sample HTTP error handling @app.errorhandler(403) def access_denied(error): return render_template('403.html'), 403 # Sample HTTP error handling @app.errorhandler(500) def server_full(error): return render_template('500.html'), 500 @app.before_request def make_session_permanent(): session.permanent = True app.permanent_session_lifetime = timedelta(minutes=5) session.modified = True @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): needs = [] if identity.id in ('viewer', 'editor', 'admin'): needs.append(to_view) if identity.id in ('editor', 'admin'): needs.append(be_editor) if identity.id == 'admin': needs.append(be_admin) for n in needs: identity.provides.add(n) # If the authenticated identity is : # - 'the_only user' she can sign in # - "the_only_editor" she can sign in and edit # - "the_only_admin" she can sign in , edit and administrate return app