Beispiel #1
0
def create_app():
    """return initialized flask app"""
    fapp = Flask(__name__)
    fapp.config["DEBUG"] = True
    fapp.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    fapp.config.from_envvar('YOURAPPLICATION_SETTINGS')
    db.init_app(fapp)
    ma.init_app(fapp)
    compress.init_app(fapp)
    FontAwesome(fapp)
    fapp.register_blueprint(auth.auth)
    fapp.register_blueprint(coach.coach, url_prefix='/coaches')
    fapp.register_blueprint(tournament.tournament, url_prefix='/tournaments')
    fapp.register_blueprint(duster.duster, url_prefix='/duster')
    fapp.register_blueprint(deck.deck, url_prefix='/decks')
    fapp.register_blueprint(cracker.cracker, url_prefix='/api/cracker')


    admin = Admin(fapp, name='Management', template_mode='bootstrap3')
    # Add administrative views here
    admin.add_view(CoachView(Coach, db.session))
    admin.add_view(TournamentView(Tournament, db.session))
    # register wehook as Tournament service notifier
    Notificator("bank").register_notifier(WebHook(fapp.config['DISCORD_WEBHOOK_BANK']).send)
    Notificator("ledger").register_notifier(WebHook(fapp.config['DISCORD_WEBHOOK_LEDGER']).send)
    Notificator("achievement").register_notifier(WebHook(fapp.config['DISCORD_WEBHOOK_ACHIEVEMENTS']).send)
    Notificator("admin").register_notifier(
        WebHook(fapp.config['DISCORD_WEBHOOK_ADMIN']).send
    )
    Notificator('tournament').register_notifier(WebHook(fapp.config['DISCORD_WEBHOOK_TOURNAMENT']).send)
    BB2Service.register_agent(bb2.Agent(fapp.config['BB2_API_KEY']))
    return fapp
Beispiel #2
0
def configured_app():
    # web framework
    # web application
    # __main__
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = secret.secret_key
    # 现在 mysql root 默认用 socket 来验证而不是密码
    # uri = 'mysql+pymysql://[email protected]/bbs?charset=utf8mb4&unix_socket=/var/run/mysqld/mysqld.sock'
    uri = 'mysql+pymysql://root:{}@localhost/bbs?charset=utf8mb4'.format(
        secret.database_password)
    # uri = 'mysql+pymysql://root:[email protected]/bbs'
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    app.config['MAIL_SERVER'] = 'smtp.gmail.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = '******'
    app.config['MAIL_PASSWORD'] = secret.mail_password

    mail.init_app(app)

    register_routes(app)
    return app
Beispiel #3
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = config.secret_key

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/web19?charset=utf8mb4'.format(
            secret.database_password)
    db.init_app(app)

    # module = __import__('routes.index')
    # b = getattr(getattr(module, 'index'), 'blueprint')()
    # log('index blueprint', b)
    # app.register_blueprint(b)
    # log('url map', app.url_map)
    app.register_blueprint(index_routes)
    app.register_blueprint(topic_routes, url_prefix='/topic')
    app.register_blueprint(reply_routes, url_prefix='/reply')
    app.register_blueprint(mail_routes, url_prefix='/mail')

    app.template_filter()(count)
    app.template_filter()(format_time)
    app.errorhandler(404)(not_found)

    admin = Admin(app, name='web19', template_mode='bootstrap3')
    admin.add_view(ModelView(User, db.session))
    admin.add_view(ModelView(Topic, db.session))
    admin.add_view(ModelView(Reply, db.session))
    admin.add_view(ModelView(Messages, db.session))
    # Add administrative views here

    return app
Beispiel #4
0
def configured_app():
    # web framework
    # web application
    # __main__
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = secret.secret_key

    uri = 'mysql+pymysql://root:{}@localhost/bbs?charset=utf8mb4'.format(
        secret.database_password)
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    app.template_filter()(time_elapsed)

    app.errorhandler(401)(auth_failed)

    db.init_app(app)
    socketio.init_app(app)

    register_routes(app)
    CORS(app, supports_credentials=True)

    return app
Beispiel #5
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = secret.secret_key

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/bbs?charset=utf8mb4'.format(
            secret.database_password)
    db.init_app(app)
    mail.init_app(app)

    # 注册蓝图
    # 有一个 url_prefix 可以用来给蓝图中的每个路由加一个前缀
    app.register_blueprint(index_routes)
    app.register_blueprint(topic_routes, url_prefix='/topic')
    app.register_blueprint(reply_routes, url_prefix='/reply')
    app.register_blueprint(user_routes, url_prefix='/user')
    app.register_blueprint(message_routes, url_prefix='/message')

    app.template_filter()(count)
    app.template_filter()(formatted_time)

    # admin = Admin(app, name='web21', template_mode='bootstrap3')
    # admin.add_view(ModelView(User, db.session))
    # admin.add_view(ModelView(Topic, db.session))
    # admin.add_view(ModelView(Reply, db.session))
    # admin.add_view(ModelView(Messages, db.session))
    # Add administrative views here

    return app
Beispiel #6
0
def configured_app():
    app = Flask(__name__)
    app.secret_key = secret.secret_key

    uri = 'mysql+pymysql://[email protected]/flask_bbs?charset=utf8mb4&unix_socket=/var/run/mysqld/mysqld.sock'

    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    # app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/flask_bbs?charset=utf8mb4'.format(
    #    secret.database_password
    #)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    '''
    app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = config.admin_mail
    app.config['MAIL_PASSWORD'] = secret.mail_password

    mail.init_app(app)
    '''
    admin = Admin(app, name='bbs admin', template_mode='bootstrap3')
    u = UserModelView(User, db.session)
    u.column_searchable_list = ["username", "password"]
    admin.add_view(u)
    b = BoardModelView(Board, db.session)
    b.column_searchable_list = ["title"]
    admin.add_view(b)
    app.permanent_session_lifetime = timedelta(minutes=60)
    register_routes(app)
    return app
Beispiel #7
0
def configured_app():
    app = Flask(__name__)

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/{}?charset=utf8mb4'.format(
            secret.database_password,
            db_name,
        )
    db.init_app(app)

    app.register_blueprint(index_routes)
    app.register_blueprint(topic_routes, url_prefix='/topic')
    app.register_blueprint(reply_routes, url_prefix='/reply')
    app.register_blueprint(user_routes, url_prefix='/user')
    app.register_blueprint(mail_routes, url_prefix='/mail')
    app.register_blueprint(reset_routes, url_prefix='/reset')
    log('url map', app.url_map)

    app.template_filter()(count)
    app.template_filter()(format_time)
    app.errorhandler(404)(not_found)

    admin = Admin(app, name=db_name, template_mode='bootstrap3')
    admin.add_view(ModelView(User, db.session))
    admin.add_view(ModelView(Topic, db.session))
    admin.add_view(ModelView(Reply, db.session))
    admin.add_view(ModelView(Board, db.session))

    return app
Beispiel #8
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    app.secret_key = secret.flask_session_secret_key

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/forum_data?charset=utf8mb4'.format(
            secret.database_password)
    # 新特性
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # 与官方推荐初始化方式不同
    # 相当于延迟加载,避免循环引用
    db.init_app(app)
    # mail.init_app(app)
    register_routes(app)

    app.template_filter()(count)
    app.template_filter()(format_time)
    app.errorhandler(404)(not_found)

    # Add administrative views here
    admin = Admin(app, name='forum admin', template_mode='bootstrap3')
    admin.add_view(ModelView(User, db.session))
    admin.add_view(ModelView(Topic, db.session))
    admin.add_view(ModelView(Reply, db.session))

    return app
Beispiel #9
0
def configured_app():
    db_name = config.db_name
    app = Flask(__name__)
    # set secret_key for flask session
    app.secret_key = secret.secret_key
    # data return order
    #mysql -> pymysql -> sqlalchemy -> route
    #initialization order
    #app -> flask-sqlalchemy -> sqlalchemy -> pymysql -> mysql

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/{}?charset=utf8mb4'.format(
            secret.mysql_password,
            db_name,
        )
    db.init_app(app)

    app.template_filter()(remove_script)
    # app.context_processor(current_time)
    app.template_filter()(format_time)
    # app.errorhandler(404)(not_found)

    admin = Admin(app, name=db_name, template_mode='bootstrap3')
    mv = UserModelView(User, db.session)
    admin.add_view(mv)
    mv = ModelView(Board, db.session)
    admin.add_view(mv)

    register_routes(app)
    return app
Beispiel #10
0
def configured_app():
    app = Flask(__name__)
    # 设置session的secret_key
    app.secret_key = config.secret_key

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/BBS?charset=utf8mb4'.format(
            secret.database_password)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    socketio.init_app(app)

    # 注册蓝图
    app.register_blueprint(index_routes)
    app.register_blueprint(topic_routes, url_prefix='/topic')
    app.register_blueprint(reply_routes, url_prefix='/reply')
    app.register_blueprint(message_routes, url_prefix='/mail')
    app.register_blueprint(chat_routes, url_prefix='/chatroom')

    # 注册过滤器
    app.template_filter()(count)
    app.template_filter()(format_time)
    app.errorhandler(404)(not_found)

    admin = Admin(app, name='bbs', template_mode='bootstrap3')
    admin.add_view(ModelView(User, db.session))
    admin.add_view(ModelView(Topic, db.session))
    admin.add_view(ModelView(Reply, db.session))

    return app
Beispiel #11
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    app.secret_key = config.secret_key
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/web19?charset=utf8mb4'.format(
        secret.database_password
    )
    db.init_app(app)

    app.register_blueprint(index_routes)
    app.register_blueprint(user_routes)
    app.register_blueprint(forget_routes, url_prefix='/forget')
    app.register_blueprint(topic_routes, url_prefix='/topic')
    app.register_blueprint(reply_routes, url_prefix='/reply')
    app.register_blueprint(mail_routes, url_prefix='/mail')
    app.register_blueprint(info_routes, url_prefix='/info')

    app.template_filter()(count)
    app.template_filter()(format_time)
    app.template_filter()(how_long_ago)

    app.template_global()(current_user)
    app.errorhandler(404)(not_found)

    admin = Admin(app, name='Swordman BBS')
    admin.add_view(ModelView(User, db.session))
    admin.add_view(ModelView(Topic, db.session))
    admin.add_view(ModelView(Reply, db.session))

    return app
Beispiel #12
0
def configured_app():
    # web framework
    # web application
    # __main__
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = secret.secret_key

    uri = 'mysql+pymysql://root:{}@localhost/web21?charset=utf8mb4'.format(
        secret.database_password
    )
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    app.template_filter()(count)
    app.template_filter()(format_time)

    admin = Admin(app, name='web20 admin', template_mode='bootstrap3')
    mv = UserModelView(User, db.session)
    admin.add_view(mv)
    mv = ModelView(Board, db.session)
    admin.add_view(mv)
    mv = ModelView(Topics, db.session)
    admin.add_view(mv)
    mv = ModelView(Replys, db.session)
    admin.add_view(mv)
    mv = ModelView(Messages, db.session)
    admin.add_view(mv)

    register_routes(app)
    return app
Beispiel #13
0
def configured_app():
    app = Flask(__name__)

    app.secret_key = secret.secret_key

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://{}:{}@{}/{}?charset=utf8mb4'.format(
            os.environ['DATABASE_USERNAME'],
            secret.database_password,
            os.environ['DATABASE_IP'],
            os.environ['DATABASE'],
        )

    db.init_app(app)

    # api = Api(hello_routes, doc='/doc/')
    #
    # register_resources(api)
    register_routes(app)
    register_filter(app)
    register_admin(app)

    return app
Beispiel #14
0
def configured_app():
    app = Flask(__name__)
    app.secret_key = config.secret_key

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/cwm?charset=utf8mb4'.format(
            secret.database_password)
    db.init_app(app)

    app.register_blueprint(index_routes)
    app.register_blueprint(topic_routes, url_prefix='/topic')
    app.register_blueprint(reply_routes, url_prefix='/reply')
    app.register_blueprint(mail_routes, url_prefix='/mail')
    app.register_blueprint(setting_routes, url_prefix='/setting')

    app.template_filter()(count)
    app.template_filter()(format_time)
    app.errorhandler(404)(not_found)

    admin = Admin(app, name='cwm', template_mode='bootstrap3')
    mv = UserModelView(User, db.session)
    admin.add_view(mv)
    mv = ModelView(Board, db.session)
    admin.add_view(mv)
    mv = ModelView(Topic, db.session)
    admin.add_view(mv)
    mv = ModelView(Reply, db.session)
    admin.add_view(mv)

    return app
Beispiel #15
0
def configured_app():
    # web framework
    # web application
    # __main__
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = secret.secret_key

    # 现在 mysql root 默认用 socket 来验证而不是密码
    uri = 'mysql+pymysql://root:{}@127.0.0.1/web21?charset=utf8mb4'.format(secret.database_password)
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = config.admin_mail
    app.config['MAIL_PASSWORD'] = secret.mail_password

    mail.init_app(app)
    redis_store.init_app(app)
    moment = Moment(app)
    bootstrap = Bootstrap(app)

    register_template_func(app)
    register_routes(app)
    return app
Beispiel #16
0
def configured_app():
    app = Flask(__name__)

    # session密钥
    app.secret_key = secret.session_secret_key

    # sqlalchemy连接数据库
    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost:3306/webnews?charset=utf8mb4'.format(
            secret.database_password)
    db.init_app(app)

    # 配置flask-admin
    admin = Admin(app, name='无权限', template_mode='bootstrap3')
    admin.add_view(MyModelView(User, db.session))
    admin.add_view(MyModelView(News, db.session))
    admin.add_view(MyModelView(Topic, db.session))
    admin.add_view(MyModelView(Reply, db.session))

    # 注册路由
    register_routes(app)

    #设置jinja2自定义过滤器
    app.template_filter()(count)
    app.template_filter()(format_time)

    # socket聊天室
    socketio.init_app(app)

    app.debug = True

    return app
Beispiel #17
0
def configured_app():
    # web framework
    # web application
    # __main__
    app = Flask(__name__)
    app.secret_key = secret.secret_key

    uri = 'mysql+pymysql://[email protected]/websx?charset=utf8mb4&unix_socket=/var/run/mysqld/mysqld.sock'
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = config.admin_mail
    app.config['MAIL_PASSWORD'] = secret.mail_password

    mail.init_app(app)

    register_routes(app)
    app.template_filter()(count)
    app.template_filter()(format_time)
    app.template_filter()(image1)
    app.template_filter()(name1)
    return app
Beispiel #18
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    app.secret_key = secret.secret_key

    uri = 'mysql+pymysql://root:{}@localhost/belife?charset=utf8mb4'.format(
        secret.database_password
    )
    # 用于连接数据库
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    # 如果设置成True(默认),Flask-SQLAlchemy 将会追踪对象的修改并且发送信号
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    # 初始化数据库
    db.init_app(app)

    # 自定义过滤器
    app.template_filter()(format_time)

    # flask-mail扩展发送电子邮件
    app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = config.admin_mail
    app.config['MAIL_PASSWORD'] = secret.mail_password
    mail.init_app(app)

    register_routes(app)
    return app
Beispiel #19
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串是啥都行
    app.secret_key = config.secret_key

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/myweb?charset=utf8mb4'.format(
            secret.database_password)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    mail.init_app(app)

    app.register_blueprint(index_routes)
    app.register_blueprint(topic_routes, url_prefix='/topic')
    app.register_blueprint(reply_routes, url_prefix='/reply')
    app.register_blueprint(todo_routes, url_prefix='/todo')
    app.register_blueprint(board_routes, url_prefix='/board')
    app.register_blueprint(todo_api)
    app.register_blueprint(mail_routes, url_prefix='/mail')

    app.template_filter()(count)

    admin = Admin(app, name='myweb', template_mode='bootstrap3')
    admin.add_view(ModelView(User, db.session))
    admin.add_view(ModelView(Topic, db.session))
    admin.add_view(ModelView(Reply, db.session))
    admin.add_view(ModelView(Todo, db.session))
    admin.add_view(ModelView(Token, db.session))
    admin.add_view(ModelView(Messages, db.session))
    admin.add_view(ModelView(Board, db.session))
    # Add administrative views here

    return app
Beispiel #20
0
def create_app():
    app = Flask(__name__)
    app.config["DEBUG"] = True
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config.from_envvar('YOURAPPLICATION_SETTINGS')
    db.init_app(app)
    ma.init_app(app)
    
    # register wehook as Tournament service notifier
    NotificationService.register_notifier(WebHook(app.config['DISCORD_WEBHOOK_BANK']).send)
    return app
Beispiel #21
0
def db_init(app):
    """
    初始化数据库
    """
    uri = 'mysql+pymysql://root:{}@localhost/{}?charset=utf8mb4'.format(
        secret.database_password,
        config.database_name,
    )
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
Beispiel #22
0
def configured_app():
    app = Flask(__name__)
    app.secret_key = secret.secret_key

    uri = 'mysql+pymysql://root:{}@localhost/web21?charset=utf8mb4'.format(
        secret.database_password)
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    register_routes(app)
    return app
Beispiel #23
0
def _app(request):
    app = create_app('test')
    app.config['DEBUG'] = True
    app.config['TESTING'] = True

    with Postgresql() as postgresql:
        app.config['SQLALCHEMY_DATABASE_URI'] = postgresql.url()

        with app.app_context():
            db.init_app(app)
            db.create_all()
            populate(db)
            yield app
Beispiel #24
0
def create_app():
    app = Flask(__name__)
    app.config["DEBUG"] = True
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config.from_envvar('YOURAPPLICATION_SETTINGS')
    db.init_app(app)
    ma.init_app(app)
    
    # register wehook as Tournament service notifier
    NotificationService.register_notifier(WebHook(app.config['DISCORD_WEBHOOK_BANK']).send)
    LedgerNotificationService.register_notifier(WebHook(app.config['DISCORD_WEBHOOK_LEDGER']).send)
    AchievementNotificationService.register_notifier(WebHook(app.config['DISCORD_WEBHOOK_ACHIEVEMENTS']).send)
    BB2Service.register_agent(Agent(app.config['BB2_API_KEY']))
    return app
Beispiel #25
0
def configured_app():
    app = Flask(__name__)

    app.secret_key = secret.secret_key
    register_routes(app)

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/{}?charset=utf8mb4'.format(
            secret.mysql_password, secret.project_name)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    db.init_app(app)
    mail.init_app(app)

    return app
Beispiel #26
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    app.secret_key = secret.secret_key

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/{}?charset=utf8mb4'.format(
            secret.database_password, secret.database_name)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    mail.init_app(app)
    admin.init_app(app)

    register_routes(app)
    return app
Beispiel #27
0
def configured_app():
    app = Flask(__name__)
    app.secret_key = appConfig.secret_key
    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@127.0.0.1:3306/test?charset=utf8mb4'.format(
            urllib.parse.quote_plus(dbConfig.password))
    # mails configuration
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    register_routes(app)
    app.template_filter()(myfirst)
    app.template_filter()(formatte_time)
    app.template_filter()(date_time)
    app.template_filter()(safe_str)
    app.json_encoder = CustomJSONEncoder
    return app
Beispiel #28
0
def create_app():
    """return initialized flask app"""
    fapp = Flask(__name__)
    fapp.config["DEBUG"] = True
    fapp.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    fapp.config.from_envvar('YOURAPPLICATION_SETTINGS')
    db.init_app(fapp)

    AdminNotificationService.register_notifier(
        WebHook(fapp.config['DISCORD_WEBHOOK_ADMIN']).send)
    StockNotificationService.register_notifier(
        WebHook(fapp.config['DISCORD_WEBHOOK_STOCK']).send)

    OrderNotificationService.register_notifier(
        WebHook(fapp.config['DISCORD_WEBHOOK_ORDER']).send)

    return fapp
Beispiel #29
0
def configured_app():
    # web framework
    # web application
    # __main__
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = secret.secret_key

    uri = 'mysql+pymysql://root:{}@localhost/web21?charset=utf8mb4'.format(
        secret.database_password)
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    register_routes(app)
    return app
Beispiel #30
0
def create_app(config_path=None, name=None):
    """Creates a flask application instance and loads its config from config_path

    :param config_path: A string representing either a file path or an import path
    :returns: An instance of `flask.Flask`."""

    app = Flask(name or __name__)
    app.config.from_object('server.config.DebugConfig')
    app.config.from_envvar(config_path or '', silent=True)

    db.init_app(app)

    admin_blueprint = admin.create_admin_blueprint(MANAGED_MODELS, db.session)
    app.register_blueprint(admin_blueprint, url_prefix="/tables")

    autoload(app)

    return app
Beispiel #31
0
# Unescape html comments

import time
import datetime
from datetime import timezone
from dateutil import tz

#pprint(var)
from pprint import pprint

app = Flask(__name__)
db_host, db_username, db_password, db_database = connection()
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://' + db_username + ':' + db_password + '@' + db_host + '/' + db_database
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SECRET_KEY'] = 'C*<$UH<#H*(UH9mu<(#*)M)#(MIoPhD+'
db.init_app(app)

app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html')

@app.route('/index')
@app.route('/')
def index():
    category = Category.query.all()

    gc.collect()
    return render_template('index.html', categories = category)