Exemple #1
0
def create_app():
    app = ApiFlask(__name__)
    app.config.from_object(config)
    db.init_app(app)

    app.register_blueprint(settings.bp)

    return app
Exemple #2
0
def create_app():
     app = ApiFlask(__name__)
     app.config.from_object(config)
     db.init_app(app)

     app.register_blueprint(settings.bp)

     return app
Exemple #3
0
def create_app():
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(settings.DevelopmentConfig)
    app.register_blueprint(user_bp)
    db.init_app(app)
    return app
def create_app():
    app = Flask(__name__)
    app.config.from_object(config.DevelopmentConfig)
    api.init_app(app)
    db.init_app(app)
    mail.init_app(app)
    CORS(app)
    return app
Exemple #5
0
def create_app():
    conf = get_config()
    app = Flask(__name__)
    app.config.update(conf['ENV'][os.getenv('ENV')])
    db.init_app(app)
    mail.init_app(app)
    cache.init_app(app,config=conf['CACHE_CONFIG'])
    return app
Exemple #6
0
def create_app():
    app = Flask(__name__, template_folder='templates', static_folder='static')
    app.config.from_object(config)
    db.init_app(app)
    app.register_blueprint(backend.bd)
    app.wsgi_app = DispatcherMiddleware(app.wsgi_app,
                                        OrderedDict((('/j', json_api), )))

    return app
Exemple #7
0
def register_extensions(app):
    bootstrap.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    csrf.init_app(app)
    ckeditor.init_app(app)
    moment.init_app(app)
    toolbar.init_app(app)
    migrate.init_app(app, db)
Exemple #8
0
def create_app():
    app = ApiFlask(
        __name__,
        template_folder='../../templates')  # 以当前app模块所在路径开始计算模板文件夹所在路径 # noqa
    app.config.from_object('config')  # 但加载`config.py`却是在程序开始运行处
    db.init_app(app)
    security.init_app(app, user_datastore)

    return app
Exemple #9
0
def create_app():
    app = Flask(__name__, template_folder='../templates', static_folder='../static')
    app.config.from_object(settings.Development)
    db.init_app(app)
    CORS(app)
    app.register_blueprint(user_api)
    app.register_blueprint(interface)
    app.register_blueprint(project_Bp)
    return app
def create_app():
    app = Flask(__name__, template_folder='../templates')
    app.config.from_object(setting.DevelopmentConfig)

    db.init_app(app)  # 将db对象对象与app进行关联
    # 注册蓝图
    app.register_blueprint(user_bp)

    return app
Exemple #11
0
def create_app(config_class=Config):
    app = Flask(__name__)
    # app.config['SECRET_KEY']='dai3hoahudhiuahduiah'
    # app.config['BABEL_DEFAULT_LOCALE'] = 'zh_Hans_CN'
    app.config.from_object(config_class)

    db.init_app(app)
    migrate.init_app(app, db)
    login.init_app(app)
    mail.init_app(app)
    bootstrap.init_app(app)
    moment.init_app(app)
    babel.init_app(app)
    app.elasticsearch = Elasticsearch([app.config['ELASTICSEARCH_URL']]) \
        if app.config['ELASTICSEARCH_URL'] else None
    from app.errors import bp as errors_bp
    app.register_blueprint(errors_bp)

    from app.auth import bp as auth_bp
    app.register_blueprint(auth_bp, url_prefix='/auth')

    from app.main import bp as main_bp
    app.register_blueprint(main_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/microblog.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('Microblog startup')
    return app
Exemple #12
0
def creat_app():
    # 创建app,并设置模板跟静态文件路径
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(settings)  # 加载配置
    db.init_app(app)  # 将db对象与app进行关联
    app.register_blueprint(user_dp)  # 注册蓝图

    return app
Exemple #13
0
def create_app():
    app = Flask(__name__,
                static_folder='../static',
                template_folder='../templates')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.register_blueprint(blueprint=blue)
    Bootstrap(app)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
    db.init_app(app)
    return app
Exemple #14
0
def create_app():
    # 创建app,并且指定templates、static文件夹位置,一般跟创建apps的目录同级,为了好看放在外面了,或者把文件夹放进来
    app = Flask(__name__, template_folder='../templates', static_folder='../static')  # app,一个核心对象
    app.config.from_object(settings)  # 加载配置
    db.init_app(app)  # 将db对象与app进行关联

    # 蓝图
    app.register_blueprint(user_bp)  # 将蓝图对象注册到app

    return app  # 返回app对象
def create_app():
    app = Flask(__name__)
    app.config.from_pyfile("settings.py")
    app.register_blueprint(main_blueprint)
    db.init_app(app)
    bootstrap.init_app(app)
    recordLog.init_app(app)
    loginManager.init_app(app)
    loginManager.login_view = 'main.login'  # 注意使用loginManager多了一步,指定视图函数
    return app
def create_app(default_settings=None):
    if default_settings is None:
        default_settings = settings
    app = Flask(__name__)
    app.config.from_object(default_settings)
    app.debug = app.config['DEBUG']
    db.init_app(app)
    app.register_blueprint(names_bp, url_prefix='/')
    posts_init_app(app)
    return app
Exemple #17
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config['development'])
    app.config.update(RESTFUL_JSON=dict(ensure_ascii=False))

    db.init_app(app)

    app.register_blueprint(api_bp)
    app.register_blueprint(home.home_bp)

    return app
Exemple #18
0
def create_app():
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    # app是一个核心对象,设置模板文件夹以及静态文件夹,路径为apps的上级目录hello_flask的的子目录
    app.config.from_object(settings.DevelopmentConfig)  # 加载配置改为类
    db.init_app(app)  # 将db对象和app进行关联
    # 注册蓝图对象 需要手动注册蓝图,才会建立上url和视图函数的映射关系
    app.register_blueprint(user_bp)

    return app
Exemple #19
0
def create_app(config):
    app = ApiFlask(__name__, static_folder=config.STATIC_FOLDER)
    app.config.from_object(config)

    db.init_app(app)
    swagger.init_app(app)
    sentry.init_app(app)

    app.register_blueprint(api_bp)
    app.register_blueprint(admin_bp)

    return app
Exemple #20
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    cache.init_app(app)
    db.init_app(app)
    db.app = app
    login_manager.init_app(app)
    mail.init_app(app)
    setup_themes(app)
    Mobility(app)

    from .utils.filters import register_filters
    register_filters(app)

    from .utils.processors import utility_processor
    app.context_processor(utility_processor)

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

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .account import account as auth_blueprint
    app.register_blueprint(auth_blueprint, url_prefix='/account')

    from .admins import admin
    admin.init_app(app)

    @app.route('/favicon.ico')
    def favicon():
        return send_from_directory(app.static_folder,
                                   'favicon.ico',
                                   mimetype='image/vnd.microsoft.icon')

    @app.route('/robots.txt')
    def robotstxt():
        return send_from_directory(app.static_folder, 'robots.txt')

    # 暂时解决因Gunicorn中引发ERROR 11而无法正常提交的问题
    #@app.teardown_request
    #def teardown_request(response_or_exc):
    #    if app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN']:
    #        try:
    #            db.session.commit()
    #        except:
    #            db.session.rollback()
    #    db.session.remove()

    return app
Exemple #21
0
def init_app(app):
    db.init_app(app)
    mail.init_app(app)
    debug_bar.init_app(app)
    _state = security.init_app(
        app,
        user_datastore,
        confirm_register_form=ExtendedRegisterForm,
        login_form=ExtendedLoginForm,
    )
    security._state = _state
    app.security = security
    security.send_mail_task(send_mail)
Exemple #22
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    cache.init_app(app)
    db.init_app(app)
    db.app = app
    login_manager.init_app(app)
    mail.init_app(app)
    setup_themes(app)
    Mobility(app)

    from .utils.filters import register_filters
    register_filters(app)

    from .utils.processors import utility_processor 
    app.context_processor(utility_processor)

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

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .account import account as auth_blueprint
    app.register_blueprint(auth_blueprint, url_prefix='/account')

    from .admins import admin
    admin.init_app(app)

    @app.route('/favicon.ico')
    def favicon():
        return send_from_directory(app.static_folder, 'favicon.ico',
                                   mimetype='image/vnd.microsoft.icon')

    @app.route('/robots.txt')
    def robotstxt():
        return send_from_directory(app.static_folder, 'robots.txt')

    # 暂时解决因Gunicorn中引发ERROR 11而无法正常提交的问题
    #@app.teardown_request
    #def teardown_request(response_or_exc):
    #    if app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN']:
    #        try:
    #            db.session.commit()
    #        except:
    #            db.session.rollback()
    #    db.session.remove()

    return app
Exemple #23
0
def create_app():
    app = Flask(__name__, template_folder='templates',
                static_folder='static')
    app.config.from_object(config)
    mako.init_app(app)
    db.init_app(app)
    app.session_interface = RedisSessionInterface(cache)
    app.register_blueprint(backend.bp)

    app.wsgi_app = DispatcherMiddleware(app.wsgi_app, OrderedDict((
        ('/j', json_api),
    )))

    return app
def create_app():
    app = Flask(__name__)
    app.config['UPLOAD_FOLDER'] = config.UPLOAD_FOLDER
    app.config['MAX_CONTENT_LENGTH'] = config.MAX_CONTENT_LENGTH
    app.config['SQLALCHEMY_DATABASE_URI'] = config.SQLALCHEMY_DATABASE_URI
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    with app.app_context():
        db.create_all()

    album.register_api(app)
    task.register_api(app)

    return app
Exemple #25
0
def create_app():
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    #环境的设置
    app.config.from_object(settings.DevelopmentConfig)
    #初始化db
    db.init_app(app)
    #初始化缓存文件
    cache.init_app(app=app, config=config)
    #初始化bootstrap
    bootstrap.init_app(app)
    app.register_blueprint(user_bp)
    app.register_blueprint(article_bp)
    return app
Exemple #26
0
def create_app():
    app.config.from_object('config')
    app.config.setdefault('SQLALCHEMY_TRACK_MODIFICATIONS', True)
    app.config['MAX_CONTENT_LENGTH'] = 3 * 1024 * 1024  # logo文件最大不能超过3M,否则返回413状态码
    db.init_app(app)

    principal.init_app(app)
    login_manager.init_app(app)
    app.register_blueprint(web, url_prefix='')  # url_prefix 不能为'/'
    app.register_blueprint(web_api_1_0_blueprint, url_prefix='/api/v1')
    # app.register_blueprint(host, url_prefix='/host_scan')
    # app.register_blueprint(port, url_prefix='/port_scan')
    app.register_blueprint(engine)

    return app
Exemple #27
0
def create_app():
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(settings.Development)
    db.init_app(app)  # 同ext.db關聯同一個app
    mail.init_app(app)
    login_manager.init_app(app)
    if not app.debug and not app.testing and not app.config['SSL_DISABLE']:
        sslify = SSLify(app)

# login_manager.session_protection = 'strong'
# 注冊blueprint
# app.register_blueprint(user_bp)
    return app
Exemple #28
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    db.init_app(app)
    db.app = app

    if not app.config['TESTING']:
        configure_custom_settings(app)
    config[config_name].init_app(app)

    thumbnail.init_app(app)
    babel.init_app(app)
    cache.init_app(app)
    login_manager.init_app(app)
    mail.init_app(app)
    setup_themes(app)
    Mobility(app)

    from .utils.filters import register_filters
    register_filters(app)

    from .utils.processors import utility_processor
    app.context_processor(utility_processor)

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

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .account import account as auth_blueprint
    app.register_blueprint(auth_blueprint, url_prefix='/account')

    from .admins import admin
    admin.init_app(app)

    @app.route('/favicon.ico')
    def favicon():
        return send_from_directory(app.static_folder,
                                   'favicon.ico',
                                   mimetype='image/vnd.microsoft.icon')

    @app.route('/robots.txt')
    def robotstxt():
        return send_from_directory(app.static_folder, 'robots.txt')

    return app
Exemple #29
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    db.init_app(app)
    db.app = app

    if not app.config['TESTING']:
        configure_custom_settings(app)
    config[config_name].init_app(app)

    thumbnail.init_app(app)
    babel.init_app(app)
    cache.init_app(app)
    login_manager.init_app(app)
    mail.init_app(app)
    setup_themes(app)
    Mobility(app)

    from .utils.filters import register_filters
    register_filters(app)

    from .utils.processors import utility_processor
    app.context_processor(utility_processor)

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

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .account import account as auth_blueprint
    app.register_blueprint(auth_blueprint, url_prefix='/account')

    from .admins import admin
    admin.init_app(app)

    @app.route('/favicon.ico')
    def favicon():
        return send_from_directory(app.static_folder, 'favicon.ico',
                                   mimetype='image/vnd.microsoft.icon')

    @app.route('/robots.txt')
    def robotstxt():
        return send_from_directory(app.static_folder, 'robots.txt')

    return app
Exemple #30
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config_name)

    db.init_app(app)
    bcrypt.init_app(app)

    @app.before_request
    def before_request():
        print('hi request')
        if 'user_id' in session:
            g.userId = session['user_id']
            print('i coming == {} =='.format(session['user_id']))
        if 'user_name' in session:
            g.username = session['user_name']

    @app.errorhandler(404)
    def api_not_found():
        response404 = copy.deepcopy(error_response)
        response404['error'] = 'api 不存在'
        return Response(json.dumps(response404),
                        404,
                        mimetype='application/json')

    @app.errorhandler(401)
    def api_not_authorized():
        response401 = copy.deepcopy(error_response)
        response401['error'] = 'api 未授权'
        return Response(json.dumps(response401),
                        401,
                        mimetype='application/json')

    @app.errorhandler(413)
    def file_too_big():
        response413 = copy.deepcopy(error_response)
        response413['error'] = '文件太大'
        return Response(json.dumps(response413),
                        413,
                        mimetype='application/json')

    app.register_blueprint(user, url_prefix='/user')
    app.register_blueprint(post, url_prefix='/post')
    app.register_blueprint(album, url_prefix='/album')

    return app
Exemple #31
0
def create_app():
    app = Flask(__name__)
    register_blueprint(app)
    bootstrap = Bootstrap(app)
    # load conffig
    app.config.from_object('secure')
    app.config.from_object('settings')

    db.init_app(app)
    with app.app_context():
        # Extensions like Flask-SQLAlchemy now know what the "current" app
        # is while within this block. Therefore, you can now run........
        db.create_all()

    login_manager.login_view = 'web.login'
    login_manager.login_message = '请先登录'
    login_manager.init_app(app)
    return app
Exemple #32
0
def creat_app():
    # app是一个核心对象,重新定义template和static文件夹位置
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(DevelopmentConfig)  # 增加配置

    # 初始化db,将db对象与app进行关联
    db.init_app(app)

    # 初始化bootstrap
    bootstrap.init_app(app=app)

    # 注册蓝图
    app.register_blueprint(user_bp)  # 将蓝图对象绑定到app上
    # print(app.url_map)

    return app
Exemple #33
0
def create_app(config_name):
    app = Flask(__name__)
    app.config['APPENV'] = str(get_appconfig())
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    cache.init_app(app)
    db.init_app(app)
    db.app = app
    login_manager.init_app(app)
    mail.init_app(app)
    setup_themes(app)
    Mobility(app)

    from .utils.filters import register_filters
    register_filters(app)

    from .utils.processors import utility_processor 
    app.context_processor(utility_processor)

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

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .account import account as auth_blueprint
    app.register_blueprint(auth_blueprint, url_prefix='/account')

    from .admins import admin
    admin.init_app(app)

    # 暂时解决因Gunicorn中引发ERROR 11而无法正常提交的问题
    @app.teardown_request
    def teardown_request(response_or_exc):
        if app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN']:
            try:
                db.session.commit()
            except:
                db.session.rollback()
        db.session.remove()

    return app
Exemple #34
0
def create_app():

    app.config.from_object('config')
    app.config.setdefault('SQLALCHEMY_TRACK_MODIFICATIONS', True)
    db.app = app
    db.init_app(app)
    if not scheduler.running:
        scheduler.init_app(app)
        scheduler.start()
    login_manager.init_app(app)

    app.register_blueprint(asset_app, url_prefix='/asset')
    app.register_blueprint(admin_app, url_prefix='')
    app.register_blueprint(inspect_app, url_prefix='/insp')
    app.register_blueprint(log_an_app, url_prefix='/log')
    app.register_blueprint(ops_app, url_prefix='/ops')
    # app.register_blueprint(asset_api_blue, url_prefix='/api/v1.0')

    return app
Exemple #35
0
def create_app():
    app = Flask(__name__)
    cors = CORS(app, resources={r"/*": {"origins": "*"}})
    app.config.from_object(settings.DevelopmentConfig)
    db.init_app(app)
    # db.create_all()

    api.init_app(app)

    # user
    app.register_blueprint(user_bp)

    # deployment
    app.register_blueprint(deployment_bp)

    print('----------------------')
    print(app.url_map)

    return app
Exemple #36
0
def create_app(config_name):
    app = Flask(__name__)

    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    db.init_app(app)

    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint, url_prefix='/api')
    from .course import course as course_blueprint
    app.register_blueprint(course_blueprint, url_prefix='/api')
    from .shop import shop as shop_blueprint
    app.register_blueprint(shop_blueprint, url_prefix='/api')
    from .video import video as video_blueprint
    app.register_blueprint(video_blueprint, url_prefix='/api')
    from .comment import comment as comment_blueprint
    app.register_blueprint(comment_blueprint, url_prefix='/api')
    return app
Exemple #37
0
 def _init_db(self, app):
     db.init_app(app)
# coding=utf-8
import logging
from logging.handlers import RotatingFileHandler

from flask import Flask, request, jsonify
from flask_sqlalchemy import get_debug_queries

from ext import db
from users import User

app = Flask(__name__)
app.config.from_object('config')
app.config['DATABASE_QUERY_TIMEOUT'] = 0.0001
app.config['SQLALCHEMY_RECORD_QUERIES'] = True
db.init_app(app)

formatter = logging.Formatter(
    "[%(asctime)s] {%(pathname)s:%(lineno)d} %(levelname)s - %(message)s")
handler = RotatingFileHandler('slow_query.log', maxBytes=10000, backupCount=10)
handler.setLevel(logging.WARN)
handler.setFormatter(formatter)
app.logger.addHandler(handler)

with app.app_context():
    db.drop_all()
    db.create_all()


@app.route('/users', methods=['POST'])
def users():
    username = request.form.get('name')