text: from flask import Flask, g
  from flask_sqlalchemy import SQLAlchemy
  from flask_login import LoginManager, current_user
  from config import config
  
  
  db = SQLAlchemy()
  login_manager = LoginManager()
  login_manager.login_view = 'main.login'
  login_manager.login_message = None
  
  from .models import User
  
  
  @login_manager.user_loader
  def load_user(user_id):
      return User.query.get(int(user_id))
  
  
  def create_app(config_name=None):
      """ The application factory method """
  
      if config_name is None:
          config_name = 'development'
  
      app = Flask(__name__)
      app.config.from_object(config[config_name])
  
      db.init_app(app)
      login_manager.init_app(app)
  
      from .app import main as main_blueprint
      app.register_blueprint(main_blueprint)
  
      from .api import api as api_blueprint
      app.register_blueprint(api_blueprint, url_prefix='/api')
  
      with app.app_context():
          return app
  