def create_app(object_name): app = Flask(__name__) app.config.from_object(object_name) db.init_app(app) login_manager.init_app(app) redis_store.init_app(app) from .controllers.task import task_blueprint from .controllers.people import people_blueprint from .controllers.weibo import weibo_blueprint from .controllers.login import login_blueprint from .controllers.circle import circle_blueprint from .controllers.errors import error_blueprints from .controllers.explore import explore_blueprint app.register_blueprint(task_blueprint, url_prefix='/task') app.register_blueprint(people_blueprint, url_prefix='/people') app.register_blueprint(weibo_blueprint, url_prefix='/wb') app.register_blueprint(login_blueprint, url_prefix='/login') app.register_blueprint(circle_blueprint, url_prefix='/circle') app.register_blueprint(explore_blueprint, url_prefix='/explore') app.register_blueprint(error_blueprints) @app.route('/') def home(): return redirect(url_for('login.check')) @app.route('/logout') def logout(): logout_user() return redirect(url_for('login.home')) return app
def init_login(): login_manager = login.LoginManager() login_manager.init_app(app) # Create user loader function @login_manager.user_loader def load_user(user_id): return db.session.query(User).get(user_id)
def register_extensions(app): """Register Flask extensions.""" assets.init_app(app) bcrypt.init_app(app) cache.init_app(app) db.init_app(app) csrf_protect.init_app(app) login_manager.init_app(app) debug_toolbar.init_app(app) migrate.init_app(app, db) return None
def create_app(object_name): """ An flask application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/ Arguments: object_name: the python path of the config object, e.g. project.config.ProdConfig """ app = Flask(__name__) app.config.from_object(object_name) rest_api.add_resource( AuthApi, '/api/auth', ) rest_api.add_resource( PostApi, '/api/post', '/api/post/<int:post_id>', ) rest_api.init_app(app) db.init_app(app) mongo.init_app(app) bcrypt.init_app(app) login_manager.init_app(app) principals.init_app(app) @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): # Set the identity user object identity.user = current_user # Add the UserNeed to the identity if hasattr(current_user, 'id'): identity.provides.add(UserNeed(current_user.id)) # Add each role to the identity if hasattr(current_user, 'roles'): for role in current_user.roles: identity.provides.add(RoleNeed(role.name)) app.register_blueprint(main_blueprint) app.register_blueprint(blog_blueprint) return app
def create_app(object_name): """ An flask application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/ Arguments: object_name: the python path of the config object, e.g. project.config.ProdConfig """ from webapp.models import db app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://*****:*****@localhost:5432/test5' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config.from_object('webapp.config.ProdConfig') #app.config.from_object('webapp.config.DevConfig') db.init_app(app) try: db.create_all() except Exception as e: print(e) bcrypt.init_app(app) oid.init_app(app) login_manager.init_app(app) principals.init_app(app) # db.create_all() app.register_blueprint(account_blueprint) app.register_blueprint(drivers_blueprint) app.register_blueprint(dvir_blueprint) app.register_blueprint(logs_blueprint) app.register_blueprint(trucks_blueprint) app.register_blueprint(elogstation_blueprint) # Create admin import flask_admin as admin1 admin = admin1.Admin(app, 'Example: Auth', index_view=MyAdminIndexView(), base_template='my_master.html') # Add view admin.add_view(MyModelView(User, db.session)) admin.add_view(MyModelView(Person, db.session)) admin.add_view(MyModelView(companyuser, db.session)) admin.add_view(MyModelView(company1, db.session)) admin.add_view(MyModelView(ELD, db.session)) return app
def create_app(object_name): app = Flask(__name__) app.config.from_object(object_name) db.init_app(app) bcrypt.init_app(app) login_manager.init_app(app) debug_toolbar.init_app(app) cache.init_app(app) rest_api = Api(app) rest_api.add_resource(PostApi, '/restapi/post', '/restapi/post/<int:post_id>', endpoint='restapi') app.register_blueprint(main_blueprint) app.register_blueprint(blog_blueprint) return app
def create_app(objecrt_name): app = Flask(__name__) app.config.from_object(objecrt_name) db.init_app(app) bcrypt.init_app(app) oid.init_app(app) login_manager.init_app(app) principlals.init_app(app) @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): # Set the identity user object identity.user = current_user # Add the UserNeed the identity if hasattr(current_user, 'id'): identity.provides.add(UserNeed(current_user.id)) # Add each role to the identity if hasattr(current_user, 'roles'): for role in current_user.roles: identity.provides.add(RoleNeed(role.name)) # 根目录重定向到蓝图 @app.route('/') def index(): return redirect(url_for('blog.home')) app.add_url_rule('/', view_func=GenericView.as_view('home', template='home.html')) # 自定义错误404页面 @app.errorhandler(404) def page_not_found(error): return render_template('page_not_found.html'), 404 app.register_blueprint(blog_blueprint) app.register_blueprint(main_blueprint) return app
def create_app(object_name): """ An flask application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/ Arguments: object_name: the python path of the config object, e.g. webapp.settings.ProdConfig env: The name of the current environment, e.g. prod or dev """ app = Flask(__name__) """SXI""" app.config.from_object(object_name) db = SQLAlchemy(app) # initialize the cache cache.init_app(app) # initialize the debug tool bar debug_toolbar.init_app(app) # initialize SQLAlchemy db.init_app(app) login_manager.init_app(app) # Import and register the different asset bundles assets_env.init_app(app) assets_loader = PythonAssetsLoader(assets) for name, bundle in assets_loader.load_bundles().items(): assets_env.register(name, bundle) # register our blueprints app.register_blueprint(main) main.app = app return app
def create_app(object_name): app = Flask(__name__) app.config.from_object(object_name) db.init_app(app) bcrypt.init_app(app) login_manager.init_app(app) principals.init_app(app) celery.init_app(app) rest_api.add_resource(PostApi, '/api/post', '/api/post/<int:post_id>', endpoint='api') rest_api.add_resource(AuthApi, '/api/auth') rest_api.init_app(app) @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): #set the identity user object identity.user = current_user #add the user need to the identity if hasattr(current_user, 'id'): identity.provides.add(UserNeed(current_user.id)) #add each role to the identity if hasattr(current_user, 'roles'): for role in current_user.roles: identity.provides.add(RoleNeed(role.name)) # @app.route('/') # def index(): # return redirect(url_for('blog.home')) app.register_blueprint(blog_blueprint) app.register_blueprint(main_blueprint) return app
def create_app(object_name, env="prod"): """ An flask application factory, as explained here: http://flask.pocoo.org/docs/patterns/appfactories/ Arguments: object_name: the python path of the config object, e.g. webapp.settings.ProdConfig env: The name of the current environment, e.g. prod or dev """ app = Flask(__name__) app.config.from_object(object_name) app.config['ENV'] = env # initialize the cache cache.init_app(app) # initialize the debug tool bar debug_toolbar.init_app(app) # initialize SQLAlchemy db.init_app(app) login_manager.init_app(app) # Import and register the different asset bundles assets_env.init_app(app) assets_loader = PythonAssetsLoader(assets) for name, bundle in assets_loader.load_bundles().items(): assets_env.register(name, bundle) # register our blueprints app.register_blueprint(main) return app
def create_app(object_name): """ """ from models import db app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///../databasetest.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config.from_object('config.ProdConfig') db.init_app(app) db.create_all() bcrypt.init_app(app) oid.init_app(app) login_manager.init_app(app) principals.init_app(app) celery.init_app(app) # Create admin import flask_admin as admin1 admin = admin1.Admin(app, 'Elogstation', index_view=MyAdminIndexView()) # Add view admin.add_view(MyModelView(User, db.session)) return app
def create_app(object_name): app = Flask(__name__) app.config.from_object(object_name) #db.init_app(app) #event.listen(Reminder, 'after_insert', on_reminder_save) db.init_app(app) bcrypt.init_app(app) login_manager.init_app(app) principals.init_app(app) celery.init_app(app) debug_toolbar.init_app(app) cache.init_app(app) admin.init_app(app) admin.add_view(CustomView(name='Custom')) models = [User,Role,Comment,Tag] for model in models: admin.add_view(CustomModelView(model,db.session,category='Models')) admin.add_view( PostView( Post, db.session, category='PostManager' ) ) admin.add_view( CustomFileAdmin( os.path.join(os.path.dirname(__file__), 'static'), '/static/', name='Static Files' ) ) rest_api.add_resource( AuthApi, '/api/auth', ) rest_api.add_resource( PostApi, '/api/post', '/api/post/<int:post_id>', ) rest_api.add_resource( CommentApi, '/api/comment', '/api/comment/<int:comment_id>', '/api/post/<int:post_id>/comment', '/api/post/<int:post_id>/comment/<int:comment_id>', ) rest_api.init_app(app) @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): # Set the identity user object identity.user = current_user print "In __init_.py......:%s" %current_user # Add the UserNeed to the identity if hasattr(current_user, 'id'): identity.provides.add(UserNeed(current_user.id)) print UserNeed(current_user.id) # Add each role to the identity if hasattr(current_user, 'roles'): for role in current_user.roles: identity.provides.add(RoleNeed(role.name)) print RoleNeed(role.name) app.register_blueprint(blog_blueprint) app.register_blueprint(main_blueprint) return app
def create_app(object_name): app = Flask(__name__) app.config.from_object(object_name) db.init_app(app) event.listen(Reminder, 'after_insert', on_reminder_save) bcrypt.init_app(app) oid.init_app(app) login_manager.init_app(app) principals.init_app(app) rest_api.add_resource(PostApi, '/api/post', '/api/post/<int:post_id>', endpoint='api') rest_api.add_resource(AuthApi, '/api/auth', endpoint='auth') rest_api.init_app(app) celery.init_app(app) debug_toolbar.init_app(app) cache.init_app(app) assets_env.init_app(app) assets_env.register("main_js", main_js) assets_env.register("main_css", main_css) admin.init_app(app) # admin.add_view(CustomView(name="Custom")) # models = [User, Role, Post, Comment, Tag, Reminder] # for model in models: # if model is not Post: # admin.add_view( # CustomModelView(model, db.session, category="models") # ) # else: # admin.add_view( # PostView(Post, db.session, category="models") # ) admin.add_view(CustomView(name='Custom')) admin.add_view(CustomModelView(User, db.session, category="Models")) admin.add_view(CustomModelView(Role, db.session, category="Models")) # # Need to use a special view for Posts to get the CKEditor functionality # admin.add_view(PostView(Post, db.session, category="Models")) admin.add_view(CustomModelView(Comment, db.session, category="Models")) admin.add_view(CustomModelView(Tag, db.session, category="Models")) admin.add_view(CustomModelView(Reminder, db.session, category="Models")) admin.add_view( CustomFileAdmin(os.path.join(os.path.dirname(__file__), 'static'), '/static/', name='Static Files')) mail.init_app(app) youtube_ext.init_app(app) # # The gzip extension and the debug toolbar can't both be running... # # flask_gzip.init_app(app) @identity_loaded.connect_via(app) def on_identity_loaded(sender, identity): identity.user = current_user if hasattr(current_user, 'id'): identity.provides.add(UserNeed(current_user.id)) if hasattr(current_user, 'roles'): for role in current_user.roles: identity.provides.add(RoleNeed(role.name)) # # Routes # @app.route('/') def index(): return redirect(url_for('blog.home')) app.register_blueprint(blog_blueprint) app.register_blueprint(main_blueprint) return app