Пример #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():
    # static_url_path-->C:\\Users\\admin\\Desktop\\PycharmProjects\\flask_example
    # app = Flask(__name__, static_url_path="")

    # static_url_path-->C:\\static
    # app = Flask(__name__, static_url_path="/static")

    app = Flask(__name__)
    # print(">>>", app.name)  # apps
    # print(">>>", app.instance_path)  # C:\Users\admin\Desktop\PycharmProjects\flask_example\instance
    # print(">>>", app.root_path)  # C:\Users\admin\Desktop\PycharmProjects\flask_example\flaskr
    app.config.from_object(config)

    from exts import db
    db.init_app(app)
    from exts import login_manager
    login_manager.init_app(app)
    from .blog import blog
    app.register_blueprint(blog)
    from .auth import auth
    app.register_blueprint(auth)
    from .test import test
    app.register_blueprint(test)
    from exceptions import exception
    app.register_blueprint(exception)

    return app
Пример #3
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
Пример #4
0
def create_app():

    app = Flask(__name__)

    app.config['SQLALCHEMY_DATABASE_URI'] = DB_URL
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    db.init_app(app)

    app.secret_key = SECRET_KEY
    login_manager.init_app(app)

    return app
Пример #5
0
def create_app():
    app = Flask('pms_falsk')
    app.secret_key = 'some_secret'
    app.config.from_object(config)

    login_manager.init_app(app)
    db.init_app(app)

    login_manager.login_view = 'auth.login'
    login_manager.login_message_category = 'info'
    login_manager.login_message = '请登陆后访问'
    app.register_blueprint(auth_bp, url_prefix='/auth')
    app.register_blueprint(pms_bp, url_prefix='/pms')
    app.register_blueprint(api_bp, url_prefix='/api')
    return app
Пример #6
0
def create_app():

    app = Flask(__name__)
    with app.app_context():
        app.config.from_object(DevConfig)

        # 初始化flask_session
        session.init_app(app)
        # 初始化cache
        cache.init_app(app)

        # 注册蓝图
        register_blueprint(app)

        # 初始化日志-按天分隔
        handler = TimedRotatingFileHandler(Config.LOG_PATH + '/flask.log',
                                           when="D",
                                           interval=1,
                                           backupCount=15,
                                           encoding="UTF-8",
                                           delay=False,
                                           utc=True)
        formatter = logging.Formatter(
            "[%(asctime)s][%(filename)s:%(lineno)d]"
            "[%(levelname)s][%(thread)d] - %(message)s")
        # 为日志记录器设置记录格式
        handler.setFormatter(formatter)
        # 为全局的日志工具对象(flaks app使用的)加载日志记录器
        # logging.getLogger().addHandler(handler)
        app.logger.addHandler(handler)

        # 初始化db
        db.app = app
        db.init_app(app)
        db.engine.pool._use_threadlocal = True
        db.Model.to_dict = db_to_dict()

        # 初始化数据库
        init_db(app)

        # 初始化flask-login
        login_manager.init_app(app)  # 初始化应用
        login_manager.login_view = 'login'  # 设置用户登录视图函数 endpoint
        if app.config["IS_MOCK_LOGIN"]:
            login_manager.anonymous_user = MyAnonymousUser

    return app
Пример #7
0
def register_extensions(main):
    db.init_app(main)
    login_manager.init_app(main)
    login_manager.login_view = 'login'

    @login_manager.user_loader
    def load_user(id):
        """
        this callback is used to reload the user object from the user
        ID stored in session
        """
        return User.query.get(int(id))

    @login_manager.unauthorized_handler
    def unauthorized_callback():
        return redirect(url_for('app.login'))

    return main
Пример #8
0
__author__ = 'XeanYu'
from flask import Flask
from conf import db_config
from exts import db
from models import Users
from main import main
from exts import login_manager

login_manager.session_protection = 'strong'
login_manager.login_view = 'main.sgin_in' # 定义验证登录页面

app = Flask(__name__)
app.config.from_object(db_config)

login_manager.init_app(app) # 传入app到login_manager进行初始化
db.init_app(app) # 初始化数据库
with app.app_context():
    db.create_all()


# 将 main 蓝本注册到 app 中
app.register_blueprint(main)

if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0',port=8080)
Пример #9
0
def init_exts(inst):
    connection.init_app(inst)
    migrate.init_app(inst, connection)
    login_manager.init_app(inst)
Пример #10
0
from wtforms import StringField, SubmitField
from wtforms.validators import DataRequired
from flask import Flask, render_template, request, redirect, url_for, session, flash, current_app, abort, send_from_directory
from models import User, Permission, Role, Category, Chapter, Course, Comment
from exts import db, login_manager, Index_pic, Chapter_PDF, Chapter_video
from flask_login import login_required, current_user, login_user, logout_user
from decorators import admin_required, permission_required, moderator_required, comment_required, leader_required
from fake import fake_users, fake_category, fake_course, fake_chapter, fake_comment
from flask_uploads import configure_uploads, patch_request_class, UploadNotAllowed
from pyecharts import Scatter3D
import random

app = Flask(__name__)
app.config.from_object(config)
db.init_app(app)
login_manager.init_app(app)
configure_uploads(app, (Index_pic, Chapter_video, Chapter_PDF))
patch_request_class(app, size=1024 * 1024 * 1024 * 4)
# set maximum file size, default is 16MB = 1024*1024*64

# TODO:add log func


def scatter3d():
    data1 = []
    for course in Course.query.all():
        data = [course.users.count(), course.num, course.comments.count()]
        data1.append(data)
    range_color = [
        '#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
        '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026'