Beispiel #1
0
def create_app():
    '''工厂方法'''
    # 创建app对象
    app = Flask(__name__)
    # 加载配置
    config = config_dict.get(app.config.get('ENV'))
    app.config.from_object(config)
    # 加载数据库配置
    from common.models import db
    db.init_app(app)
    # 记录日志信息
    log_file(config.LOG_LV)
    # redis集群加载
    from rediscluster import RedisCluster
    app.redis_cluster = RedisCluster(
        startup_nodes=app.config.get('REDIS_CLUSTER'))
    # redis哨兵,主从配置
    from redis.sentinel import Sentinel
    sentinel = Sentinel(app.config.get('REDIS_SENTINELS'))
    app.redis_master = sentinel.master_for(
        app.config.get('REDIS_SENTINEL_SERVICES_NAME'))
    app.redis_slave = sentinel.slave_for(
        app.config.get('REDIS_SENTINEL_SERVICES_NAME'))
    # 注册用户蓝图到app中
    from .resources.users import user_blue
    app.register_blueprint(user_blue)
    return app
    def __init__(self,
                 import_name,
                 template_folder=None,
                 root_path=None,
                 static_folder=None):
        super(Application, self).__init__(
            import_name,
            template_folder=template_folder,
            root_path=root_path,
            static_folder=static_folder,
        )
        self.config.from_object('config.baseSetting')
        env = platform.system()
        if env == "Linux":
            # 读取生产环境配置
            self.config.from_object('config.production')
        else:
            # 读取开发环境配置
            self.config.from_object('config.development')

        # 创建链接到redis数据库的对象
        global redis_store
        self.redis_store = redis.StrictRedis(
            host=self.config['REDIS_HOST'],
            port=self.config['REDIS_PORT'],
            password=self.config['REDIS_PARAMS'],
            db=self.config['DB'])
        db.init_app(self)
        self.config.from_object(JobsConfig())
Beispiel #3
0
def create_app(start_type):
    app = Flask(__name__)
    app.config.from_object(config[start_type])
    config[start_type].init_app(app)
    print(app.config.get("SQLALCHEMY_DATABASE_URI"))
    db.init_app(app)

    return app
def create_app(config_object):
    app = Flask(__name__)

    app.config.from_object(config_object)
    db.init_app(app)
    migrate = Migrate(app, db)

    app.register_blueprint(v1_bp, url_prefix='/v1')

    return app
Beispiel #5
0
    def __init__(self, import_name, template_folder=None, root_path=None):
        super(Application, self).__init__(import_name,
                                          template_folder=template_folder,
                                          root_path=root_path,
                                          static_folder=None)
        self.config.from_pyfile('config/base_setting.py')

        # 动态设置加载
        if 'ops_config' in os.environ:
            self.config.from_pyfile('config/%s_setting.py' %
                                    os.environ['ops_config'])

        db.init_app(self)
Beispiel #6
0
def create_app():
    app = Flask(__name__)
    app.config.from_object("common.config.DevelopmentConfig")

    CORS(app)
    # CORS(app, resource={r"/*": {"origins": "*"}})

    from common.models import db
    db.init_app(app)

    from blueprints.api.views import api_blueprint
    app.register_blueprint(api_blueprint, url_prefix='/api')

    return app
Beispiel #7
0
 def __init__(self,
              import_name,
              template_folder=None,
              root_path=None,
              static_folder=None):
     super(Application, self).__init__(
         import_name,
         template_folder=template_folder,
         root_path=root_path,
         static_folder=static_folder,
     )
     self.config.from_object('config.baseSetting')
     env = platform.system()
     if env == "Linux":
         print('**读取生产环境配置**')
         self.config.from_object('config.production')
     else:
         print('**读取开发环境配置**')
         self.config.from_object('config.development')
     db.init_app(self)
Beispiel #8
0
def create_app():
    """Factory to create the Flask application with configuration and database init."""
    app = Flask(__name__)
    load_config(app.config)
    db.init_app(app)
    return app
Beispiel #9
0
from flask import Flask
from flask_cors import CORS

from common.config import read_config
from common.models import db


config = read_config()
app = Flask(__name__)
app.config['MONGODB_SETTINGS'] = config.get('MONGO', {})
CORS(app)

db.init_app(app)

from web.api import api as api_bp
app.register_blueprint(api_bp)

from web.content import content as content_bp
app.register_blueprint(content_bp)

from web.main import main as main_bp
app.register_blueprint(main_bp)


def start_api_server() -> None:
    """ Starts the web server """

    app.run(
        host=config.get('HOST', 'localhost'),
        port=config.get('PORT', 5000),
        debug=True
from flask.ext.restful import Api

import os
from common.auth import auth
from common.models import db
from flask import Flask, request
from flask_limiter import Limiter

app = Flask(__name__)
app.config.from_object(os.environ.get('FLASK_CONFIG') or
                       'config')
api = Api(app)
db.init_app(app)
if app.config['USE_RATE_LIMITS']:
    limiter = Limiter(app, global_limits=["10 per minute"],  key_func = lambda : request.remote_addr)
    limiter = Limiter(app)

# class ResourceList(Resource):
#
#     def get(self):
#         resources_html = "<html><body>" \
#                          "<h1>Resource list: </h1>" \
#                          "<ul><li><a href='/trafficLink'>Traffic links</a></li>" \
#                          "<li><a href='/trafficSpeed'>Traffic speed</a></li>""</ul>" \
#                          "</body></html>"
#         return output_html(resources_html, 200)
#
# api.add_resource(ResourceList, '/')

# @api.errorhandler(401)
# def validation_error(e):