Пример #1
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    db.init_app(app)
    csrf.init_app(app)
    bcrypt.init_app(app)
    mail.init_app(app)
    login_manager.init_app(app)
    redis_store.init_app(app)
    celery.conf.update(app.config)

    models_committed.connect(receive_change, app)

    sign_in_manage = {}
    sign_in_func = 'account.sign_in'
    for path in blueprints:
        bp = import_string('sayit.views.' + path[0])
        app.register_blueprint(bp, url_prefix=path[1])
        sign_in_manage[bp.name] = sign_in_func

    for path in jinja_filters:
        flt = import_string('sayit.filters:' + path[0])
        app.jinja_env.filters[path[1]] = flt

    login_manager.blueprint_login_views = sign_in_manage

    return app
Пример #2
0
def create_app():
    """
    主入口文件创建app,供其他蓝图使用
    :return: 返回一个app
    """
    app = Flask(__name__)
    # 防止csrf注入攻击
    CSRFProtect(app)
    # 注册蓝图模块
    app.register_blueprint(cms_bp, url_prefix="/cms")
    app.register_blueprint(common_bp, url_prefix="/common")
    app.register_blueprint(front_bp)

    # 导入配置文件
    app.config.from_object(config)
    # 数据库db绑定到app上
    db.init_app(app)
    # 邮件mail绑定到app上
    mail.init_app(app)
    # Redis数据库cache绑定到app上
    cache.init_app(app)
    # 后台登录login_manager初始化app
    # cms_login_manager.init_app(app)
    # 前台登录login_manager绑定到app上
    front_login_manager.init_app(app)
    # login_manager.blueprint_login_views = "cms.login"
    # login_manager.blueprint_login_views = "/signin"
    front_login_manager.blueprint_login_views = {
        'cms': "cms.login",
        'front': 'front.signin'
    }

    # 富文本编辑器绑定到app上
    ckeditor.init_app(app)
    return app
Пример #3
0
def create_app():
    app = Flask(__name__)
    app.register_blueprint(cms_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(common_bp)
    app.config.from_object(config)
    CSRFProtect(app)
    db.init_app(app)
    mail.init_app(app)
    return app
Пример #4
0
def create_app():
    app = Flask(__name__)
    app.register_blueprint(cms_bp)
    app.register_blueprint(front)
    app.register_blueprint(common)
    app.config.from_object(config)
    db.init_app(app)
    mail.init_app(app)
    app.config['SECRET_KEY'] = '110'
    return app
Пример #5
0
def create_app():
    app.config.from_object(config)
    app.register_blueprint(cms_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)
    db.init_app(app=app)
    mail.init_app(app=app)
    smsapi.init_app(app=app)
    CSRFProtect(app)  # TODO: csrf保护
    return app
Пример #6
0
def create_app():
    app = Flask(__name__)
    #app.config.from_object(config.config['development'])
    # app.config.from_object(config.config['testing'])
    app.config.from_object(config.config['production'])
    app.register_blueprint(common_bp)
    db.app = app
    db.init_app(app)
    mail.init_app(app)
    return app
Пример #7
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config)  #加载配置文件
    db.init_app(app)  #初始化app
    mail.init_app(app)
    alidayu.init_app(app)
    app.register_blueprint(cms_bp)  #注册蓝图
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)
    CSRFProtect(app)  #使用CSRF 保护app
    return app
Пример #8
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config)
    app.register_blueprint(cms_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(ueditor_bp)
    db.init_app(app)
    mail.init_app(app)
    CSRFProtect(app)
    return app
Пример #9
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config)
    app.register_blueprint(cms_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(ueditor_bp)
    mail.init_app(app)
    db.init_app(app)
    CSRFProtect(app)
    Captcha.gene_graph_captcha()
    return app
Пример #10
0
def create_app(config_env):
    app = Flask(__name__)
    app.config.from_object(config[config_env])
    config[config_env].__init__(app)
    app.register_blueprint(eog_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(common_bp)
    app.permanent_session_lifetime = datetime.timedelta(seconds=60 * 60 * 3)
    db.init_app(app)
    mail.init_app(app)
    CSRFProtect(app)
    return app
Пример #11
0
def create_app():
    app = Flask(__name__)

    app.config.from_object(config)
    db.init_app(app)  #数据库绑定
    mail.init_app(app)  #邮箱
    CSRFProtect(app)  #csrf
    app.register_blueprint(cms_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(ueditor_bp)
    return app
Пример #12
0
def create_app():
    flask_app = Flask(__name__)
    flask_app.config.from_object(config)
    flask_app.register_blueprint(cms_bp)
    flask_app.register_blueprint(common_bp)
    flask_app.register_blueprint(front_bp)
    flask_app.register_blueprint(ueditor_bp)
    db.init_app(flask_app)
    mail.init_app(flask_app)
    CSRFProtect(flask_app)

    return flask_app
Пример #13
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config)

    db.init_app(app)
    app.register_blueprint(main_bp)
    app.register_blueprint(cms_bp)
    app.register_blueprint(kindeditor_bp)

    CSRFProtect(app)
    mail.init_app(app)
    return app
Пример #14
0
def create_app():
    app = Flask(__name__)
    app.register_blueprint(cms_bp)
    app.register_blueprint(front_bp)
    login_manager.init_app(app)
    app.config.from_object(config)
    db.init_app(app)
    mail.init_app(app)
    CSRFProtect(app)
    moment.init_app(app)
    bootstrap.init_app(app)
    return app
Пример #15
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config)  # 引入配置

    app.register_blueprint(cms_bp)  # 蓝图注册
    app.register_blueprint(front_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(ueditor_bp)

    db.init_app(app)  # 只要满足flask的插件,都可以通过init_app()把app引进来
    mail.init_app(app)
    CSRFProtect(app)  # 防止CSRF攻击
    return app
Пример #16
0
def create_app():

    app = Flask(__name__)
    app.config['SECRET_KEY'] = "123456"

    app.config.from_object(config)
    db.init_app(app)
    mail.init_app(app)
    CSRFProtect(app)
    app.register_blueprint(cms_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(ueditor_bp)
    return app
Пример #17
0
def create_app():
    # 实例化Flask对象:
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    CSRFProtect(app)
    # 加载配置信息:
    app.config.from_object(config)
    # app数据库初始化:
    db.init_app(app)
    mail.init_app(app)
    # 注册蓝图
    for bp in bps:
        app.register_blueprint(bp)
    return app
Пример #18
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config)
    # 注册蓝图
    app.register_blueprint(cms_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(ueditor_bp)

    db.init_app(app)
    mail.init_app(app)  # 初始化发送app
    # 注册redis
    app.redis = redis.Redis(**config.REDIS_DB_URL)
    CSRFProtect(app) # csrf防护
    return app
def create_app():
    app = Flask(__name__)
    app.register_blueprint(cms_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(ueditor_bp)
    app.config.from_object(config)


    db.init_app(app)
    mail.init_app(app)
    CSRFProtect(app)
    #自己加的,这里
    # ronglianyun.init_app(app)

    return app
Пример #20
0
def create_app():

    app = Flask(__name__)
    app.config.from_object(config)
    # config.py 配置文件
    # exts.py 装载第三库的实例对象的文件
    # models 模型文件
    # manage.py 项目运行文件
    # app包,存储蓝图(前端、后端、公共)
    app.register_blueprint(common_bp)
    app.register_blueprint(cms_bp)
    app.register_blueprint(front_bp)
    db.init_app(app)
    mail.init_app(app)
    CSRFProtect(app)
    return app
Пример #21
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config)

    # 注册蓝图
    app.register_blueprint(cms_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(common_bp)

    # 分别用db、mail、alidayu对象初始化app
    db.init_app(app)
    mail.init_app(app)
    alidayu.init_app(app)

    CSRFProtect(app)  # 这样就可以拥有CSRF保护了

    return app
Пример #22
0
def create_app():
    '''
    创建一个flaks实例,导入相关配置,注册蓝图,绑定到db、mail等库,开启CSRF保护
    :return:
    '''
    app = Flask(__name__)
    app.config.from_object(config)

    app.register_blueprint(cms_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(ueditor_bp)

    db.init_app(app)
    mail.init_app(app)

    CSRFProtect(app)
    return app
Пример #23
0
def create_app():
    # 创建app,并且指定templates、static文件夹位置
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(settings)  # 加载配置文件

    db.init_app(app)  # 初始化数据库
    csrf.init_app(app)  # 初始化全局csrf
    mail.init_app(app)  # 初始化发送邮件类
    cache.init_app(app)  # 初始化缓存

    # 注册蓝图
    app.register_blueprint(main_bp)  # 前台展示蓝图
    app.register_blueprint(user_bp)  # 用户模块蓝图
    app.register_blueprint(admin_bp)  # 后台管理蓝图

    return app
Пример #24
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(DevConfig)
    print(app.config['DEBUG'])
    db.init_app(app)
    mail.init_app(app)

    app.register_blueprint(cms_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(ueditor_bp)
    CSRFProtect(app)

    @app.errorhandler(404)
    def page_not_found(error):
        return render_template('front/404.html'), 404

    return app
Пример #25
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(config['development'])

    db.init_app(app)
    mail.init_app(app)

    from apps.front import api
    api.init_app(app)

    from apps.backend import backend as backend_blueprint
    app.register_blueprint(backend_blueprint)
    from apps.common import common as common_blueprint
    app.register_blueprint(common_blueprint)
    from apps.front import front as front_blueprint
    app.register_blueprint(front_blueprint)

    return app
Пример #26
0
def create_app():
    app = Flask(__name__)
    # 加载配置文件
    app.config.from_object(config)

    # 注册蓝图
    app.register_blueprint(cms_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(ueditor_bp)

    # 绑定SQLAlchemy
    db.init_app(app)
    # 绑定CSRF保护
    CSRFProtect(app)
    # 绑定mail
    mail.init_app(app)

    @app.errorhandler(404)
    def page_not_found(error):
        return render_template('common/error_404.html')

    @app.template_filter("time_filter")
    def time_filter(time):
        now = datetime.now()
        period = (now - time).total_seconds()
        if period < 180:
            return "刚刚"
        elif 180 <= period < 3600:
            return "%s分钟前" % int(period / 60)
        elif 3600 <= period < 86400:
            return "%s小时前" % int(period / 3600)
        elif 86400 <= period < 2592000:
            return "%s天前" % int(period / 86400)
        else:
            return time.strftime('%Y-%m-%d')

    @app.template_filter("time_simple")
    def time_simple(time):
        return time.strftime('%Y-%m-%d')

    return app
Пример #27
0
def create_app():
    app = Flask(__name__)

    # 导入config
    app.config.from_object(config)

    # 注册db
    db.init_app(app)

    # CSRF攻击
    CSRFProtect(app)

    # mail绑定app
    mail.init_app(app)
    # 注册蓝图
    app.register_blueprint(cms_bp)
    app.register_blueprint(front_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(ueditor_bp)
    return app
Пример #28
0
def create_app():
    app = Flask(__name__)
    CORS(api_bp, resources=r'/*')  # api接口允许跨域请求
    csrf.exempt(api_bp)  # api接口去除csrf保护
    # app.config.from_object(config.config['development'])   #初始化开发环境配置1
    #app.config.from_object(config.config['testing'])  # 初始化测试环境配置
    app.config.from_object(config.config['production'])
    app.config.from_object(scheduler_job.Config())
    app.register_blueprint(api_bp)
    app.register_blueprint(admin_bp)
    app.register_blueprint(common_bp)
    app.register_blueprint(front_bp)
    db.app = app
    mail.app = app

    db.init_app(app)
    mail.init_app(app)
    csrf.init_app(app)

    return app
Пример #29
0
@File: bbs_app.py
@Software: PyCharm
@Description:
"""
from flask import Flask
import config
from exts import db, mail
from apps_blueprint.cms.views import cms_bp
from apps_blueprint.common.views import common_bp
from apps_blueprint.front.views import front_bp
from flask_wtf import CSRFProtect
"""【目录结构】
cms - 后台
common - 共有
front - 前台
"""

app = Flask(__name__)
"""CSRFProtect用于保护网站:验证访问者是否为爬虫或含有csrf字符串的浏览器"""
CSRFProtect(app)  # CSRF可生成随机字符串,用于验证

app.config.from_object(config)
db.init_app(app)
mail.init_app(app)

app.register_blueprint(cms_bp)
app.register_blueprint(common_bp)
app.register_blueprint(front_bp)

if __name__ == '__main__':
    app.run(debug=True)
Пример #30
0
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from celery import Celery
from flask import Flask
import config
from flask_mail import Message
from exts import mail


app = Flask(__name__)
app.config.from_object(config)
mail.init_app(app)


def make_celery(app):
    celery = Celery(app.import_name, backend=app.config['CELERY_RESULT_BACKEND'], broker=app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)
    TaskBase = celery.Task

    class ContextTask(TaskBase):
        abstract = True

        def __call__(self, *args, **kwargs):
            with app.app_context():
                return TaskBase.__call__(self, *args, **kwargs)
    celery.Task = ContextTask
    return celery


celery = make_celery(app)
Пример #31
0
from celery import Celery
# from zlbbs import create_app #出现循环导入问题
from flask import Flask
from flask_mail import Message
from exts import mail
from utils.smssender import send_sms
import config
# celery = Celery("tasks",broker="redis://:Zc@[email protected]:6379/0",backend="redis://:Zc@[email protected]:6379/0")

app = Flask(__name__)
app.config.from_object(config)
mail.init_app(app=app)  #需要初始化才可以读取到config中对于email的配置


def make_celery(app):
    celery = Celery(app.import_name,
                    backend=app.config['CELERY_RESULT_BACKEND'],
                    broker=app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)

    class ContextTask(celery.Task):
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return self.run(*args, **kwargs)

    celery.Task = ContextTask
    return celery


celery = make_celery(app=app)
Пример #32
0
def configure_extensions(app):
    db.init_app(app)
    mail.init_app(app)
Пример #33
0
import math
from apps.cms.views import bp as cms_bp  #导入后台蓝图
from apps.common.views import bp as common_bp  #导入公共蓝图
from apps.front.views import bp as front_bp  #导入前台蓝图
from ueditor import bp as ueditor  #导入一个编辑器
from datetime import datetime

app = Flask(__name__)  #初始化程序
CSRFProtect(app)  #把app添加到CSRFProtect中
app.register_blueprint(front_bp)  #导入前台蓝图
app.register_blueprint(common_bp)  #导入公共模块蓝图
app.register_blueprint(cms_bp)  #导入后台模块蓝图
app.register_blueprint(ueditor)  #导入一个编辑器蓝图文件
app.config.from_object(config)  #导入配置文件
db.init_app(app)  #把db和app绑定在一起,使其获得config里面关于数据库的配置信息
mail.init_app(app)  #把mail和app绑定在一起,使其获得config里面关于邮箱的的配置信息


# 自定义时间模板过滤器
@app.template_filter('settime')
def settim(value):
    if isinstance(value, datetime):
        now = datetime.now()
        time = (now - value).total_seconds()
        if time < 60:  #小于60秒
            return '刚刚发布'
        elif time > 60 and time < 60 * 60:  #大于60秒小于60分钟
            sj = int(time / 60)
            return '{0}分钟前发布'.format(sj)
        elif time > 60 * 60 and time < 60 * 60 * 24:  #24小时前
            sj = int(time / (60 * 60))
Пример #34
0
# @File    : tasks.py
# @Documents:

# --pool=solo不是并发,只能作为测试用
# 在windows运行本文件命令行代码:D:\learn_tmp\flask_program_review>celery -A tasks.celery --pool=solo worker --loglevel=info
# 在linux运行本文件命令行代码:Dcelery -A tasks.celery worker --loglevel=info

from celery import Celery
from flask_mail import Message
from exts import mail
from flask import Flask
import config

flask_app = Flask(__name__)
flask_app.config.from_object(config)
mail.init_app(flask_app)


def make_celery(app):
    celery = Celery(app.import_name,
                    backend=app.config['CELERY_RESULT_BACKEND'],
                    broker=app.config['CELERY_BROKER_URL'])
    celery.conf.update(app.config)

    class ContextTask(celery.Task):
        def __call__(self, *args, **kwargs):
            with app.app_context():
                return self.run(*args, **kwargs)

    celery.Task = ContextTask
    return celery