Example #1
0
def register_extensions(app):
    bootstrap = Bootstrap(app)
    moment = Moment(app)
    db.init_app(app)
    migrate = Migrate(app, db)
    register_blueprints(app)
    mail = Mail(app)
    pagedown = PageDown()
    pagedown.init_app(app)
    login_manager = LoginManager()
    login_manager.init_app(app)
    login_manager.login_view = 'front.login'
    login_manager.session_protection = 'strong'

    @login_manager.user_loader
    def user_loader(id):
        return User.query.get(id)
Example #2
0
def create_app():
    app = Flask(__name__)

    # 各项插件的配置
    app.config['SECRET_KEY'] = 'kkk'
    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql://*****:*****@localhost/flask'  #配置数据库

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    app.config['FLASKY_FOLLOWERS_PER_PAGE'] = 5
    app.config['FLASKY_POSTS_PER_PAGE'] = 5
    app.config['FLASKY_COMMENTS_PER_PAGE'] = 5

    app.config['UPLOAD_FOLDER'] = 'E:/Python工作空间/Flasky0.1/static/avatar/'
    app.config['MAIL_DEBUG'] = True  # 开启debug,便于调试看信息
    app.config['MAIL_SUPPRESS_SEND'] = False  # 发送邮件,为True则不发送
    app.config['MAIL_SERVER'] = 'smtp.qq.com'  # 邮箱服务器
    app.config['MAIL_PORT'] = 465  # 端口
    app.config['MAIL_USE_SSL'] = True  # 重要,qq邮箱需要使用SSL
    app.config['MAIL_USE_TLS'] = False  # 不需要使用TLS
    app.config['MAIL_USERNAME'] = '******'  # 填邮箱
    app.config['MAIL_PASSWORD'] = '******'  # 填授权码
    app.config['MAIL_DEFAULT_SENDER'] = '*****@*****.**'  # 填邮箱,默认发送者
    app.config['FLASKY_MAIL_SUBJECT_PREFIX'] = '[blog]'
    app.config['FLASKY_MAIL_SENDER'] = '*****@*****.**'

    db.init_app(app)
    page_down = PageDown()
    page_down.init_app(app)
    bootstrap = Bootstrap(app)
    moment = Moment(app)
    mail.init_app(app)

    login_manger.init_app(app)

    from auth_Views import auth
    app.register_blueprint(auth, url_prefix='/auth')
    from blog_Views import blog
    app.register_blueprint(blog, url_prefix='/blog')
    return app
Example #3
0
from apps.utils import create_folder

create_folder(app.config['UPLOADED_FOLDER'])

# manager = Manager(app)
# nav.register_element('top', Navbar('flask入门',
#                                    View('主页', 'home'),
#                                    View('关于', 'about'),
#                                    View('服务', 'services'),
#                                    View('项目', 'projects')))

db.init_app(app)
bootstrap.init_app(app)
# nav.init_app(app)
login_manager.init_app(app)
pagedown.init_app(app)

Gravatar(app, size=64)  # 默认图像大小

# 注册蓝图
from apps.auth import auth as auth_blueprint
from apps.main import main as main_blueprint

app.register_blueprint(auth_blueprint, url_prefix='/auth/')
app.register_blueprint(main_blueprint)

# def create_app():
#     app = import_app()
#     app.url_map.converters['regex'] = RegexConverter
#     app.config.from_object(config)
#