Exemplo n.º 1
0
def create_app(config_name):
    app = Flask(__name__, static_url_path='/static')
    app.config.from_object(DevelopmentConfig)
    DevelopmentConfig.init_app(app)
    bootstrap.init_app(app)
    mail.init_app(app)
    moment.init_app(app)

    from main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    return app
Exemplo n.º 2
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(DevelopmentConfig)
    DevelopmentConfig.init_app(app)

    bootstrap.init_app(app)
    mail.init_app(app)
    moment.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    pagedown.init_app(app)

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .auth import auth as auth_blueprint
    # 可选参数url_prefix代表,这个蓝本中所有的路由都会加上/auth前缀
    app.register_blueprint(auth_blueprint, url_prefix='/auth')

    return app
Exemplo n.º 3
0
def create_app(config_name):
	app = Flask(__name__)
	app.config.from_object(config)
	config.init_app(app)

	mail.init_app(app)
	bootstrap.init_app(app)
	moment.init_app(app)
	db.init_app(app)
	login_manager.init_app(app)

	from .main import main as main_blueprint
	app.register_blueprint(main_blueprint)

	from .auth import auth as auth_blueprint
	app.register_blueprint(auth_blueprint, url_prefix = '/auth')

	from .post import post as post_blueprint
	app.register_blueprint(post_blueprint, url_prefix = '/post')

	return app
Exemplo n.º 4
0
def create_app(config_name):

    app = Flask(__name__, instance_relative_config=True)
    cfg = DevelopmentConfig()
    cfg.init_app(app)
    app.config.from_object(cfg)

    db.init_app(app)
    migrate = Migrate(app, db)

    db.init_app(app)
    migrate.init_app(app, db)
    login.init_app(app)

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .auth import auth as auth_blueprint
    app.register_blueprint(auth_blueprint)

    from .errors import errors as error_blueprint
    app.register_blueprint(error_blueprint)

    return app
Exemplo n.º 5
0
def csrf_update(func):
    @wraps(func)
    def wrap(*args, **kwargs):
        session['csrf_token'] = token_hex(10)
        app.jinja_env.globals['csrf_token'] = session['csrf_token']
        return func(*args, **kwargs)

    return wrap


def login_required(func):
    @wraps(func)
    def wrap(*args, **kwargs):
        if 'user' not in session:
            flash("You should log in first", 'danger')
            return redirect(url_for('index'))
        else:
            return func(*args, **kwargs)

    return wrap


app = CustomFlask(__name__)
config = DevelopmentConfig()
config.init_app(app)
app.config.from_object(config)
socketio = SocketIO(app)
mail = Mail(app)
db = Database(app)
from app import routes, models, sockets