예제 #1
0
def create_app():
    app = Flask(__name__, template_folder='../templates', static_folder='../static')
    app.config.from_object(settings.config)
    db.init_app(app=app)
    # 初始化bootstrap
    bootstrap.init_app(app=app)
    # 注册蓝图
    app.register_blueprint(user_bp)
    app.register_blueprint(article_bp)
    return app
예제 #2
0
def register_extensions(app: Flask) -> None:
    """Registering the extensions to the app object"""

    bootstrap.init_app(app)
    login.init_app(app)
    db.init_app(app)

    # Creating the database TODO this comment is dumb
    with app.app_context():
        db.create_all()
예제 #3
0
def create_app():
    app = Flask(__name__, template_folder='../templates', static_folder='../static')
    app.config.from_object(DevelopmentConfig)
    # 初始化db
    db.init_app(app=app)
    bootstrap.init_app(app)
    # 注册蓝图
    app.register_blueprint(user_bp)
    app.register_blueprint(article_bp)
    # print(app.url_map)
    return app
예제 #4
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
예제 #5
0
def create_app():
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')  # app是一个核心对象
    app.config.from_object(settings.DevelopmentConfig)
    # 注册蓝图
    app.register_blueprint(article_bp)
    app.register_blueprint(user_bp)
    # 连接数据库,1首先让db和app联系
    db.init_app(app=app)
    bootstrap.init_app(app=app)  # bootstrap和app联系

    return app
예제 #6
0
def create_app():
    app = Flask(__name__,
                template_folder='../templates',
                static_folder='../static')
    app.config.from_object(settings)
    db.init_app(app)  # 初始化db

    # 初始化csrf,需要配置SECRET_KEY
    # csrf.init_app(app=app)

    # 初始化restful api
    api.init_app(app=app)

    # 初始化cors解决跨域
    cors.init_app(app=app, supports_credentials=True)  # 后面是支持证书认证

    # 初始化缓存文件
    cache.init_app(
        app=app,
        config={
            'CACHE_TYPE': 'redis',  # 缓存类型
            # 'CACHE_REDIS_HOST': 'localhost',  # 地址,默认使用0号数据库
            # 'CACHE_REDIS_PORT': 6379  # 端口号
            'CACHE_REDIS_URL':
            'redis://@localhost:6379/2'  # 无密码, 有密码:redis://user:password@localhost:6379/2
        })

    # 初始化bootstrap两种方法
    bootstrap.init_app(app)
    # Bootstrap(app)

    # 注册蓝图(模块:user_app,blog_app...)
    app.register_blueprint(app_bp)
    app.register_blueprint(user_bp)
    app.register_blueprint(restful_bp)
    app.register_blueprint(api_user_bp)

    return app
예제 #7
0
from flask import Flask
import config
from exts import bootstrap, csrf, db
from flask import flash, render_template, redirect, url_for, request
from flask_bootstrap import Markup
from formModel import GetForm, GetFormField
from sqlModel import User

app = Flask(__name__)
app.config.from_object(config)
bootstrap.init_app(app=app)
csrf.init_app(app=app)
db.init_app(app=app)


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/get_flash_messages/', methods=['GET', 'POST'])
def get_flash_messages():
    flash('A simple default alert—check it out!')
    flash('A simple primary alert—check it out!', 'primary')
    flash('A simple secondary alert—check it out!', 'secondary')
    flash('A simple success alert—check it out!', 'success')
    flash('A simple danger alert—check it out!', 'danger')
    flash('A simple warning alert—check it out!', 'warning')
    flash('A simple info alert—check it out!', 'info')
    flash('A simple light alert—check it out!', 'light')
    flash('A simple dark alert—check it out!', 'dark')