示例#1
0
文件: core.py 项目: Maslastja/test
def create_app():
    app = Flask('app',
                root_path=os.getcwd(),
                static_folder='static',
                template_folder='app/templates')
    app.config.from_object('config.settings')
    db.init_app(app)
    register_bp(app)
    if not app.debug:
        logapp(app)

#    app.session_interface = MySessionInterface()
# app.jinja_env.filters['formatdatetime'] = format_datetime

    @app.before_request
    def before_request():
        # print(session)
        bp = request.blueprint or request.endpoint
        if bp in ('auth', 'static'):
            return
        if bp == 'admin' and not session.user:
            return redirect('/')

    if not app.debug:

        @app.errorhandler(Exception)
        def handle_error(e):
            if type(e) == NotFound:
                code = 404
            else:
                code = 500
            return render_template(f'{str(code)}.html'), code

    return app
示例#2
0
def create_app(configuration='Production'):
    from config.database import db  # Avoid circular imports

    settings = f'config.settings.{configuration}'

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

    db.init_app(app)
   
    register_blueprints(app)

    return app
示例#3
0
def create_app():
    app = Flask('app',
                root_path=os.getcwd(),
                static_folder='static',
                template_folder='app/templates')

    app.config.from_object('config.settings')
    db.init_app(app)
    register_bp(app)
    if not app.debug:
        logapp(app)

    app.session_interface = MyDatabaseSessionInterface()

    @app.before_request
    def before_request():
        bp = request.blueprint or request.endpoint
        if bp in ('auth', 'static'):
            return
        if not session.user:
            return redirect(url_for('auth.login', next=request.url
                                    or 'static'))

    @app.after_request
    def after_request(response):
        s = session.exist_session()
        if s:
            session.change_last_req()
        return response

    if not app.debug:

        @app.errorhandler(Exception)
        def handle_error(e):
            if type(e) == NotFound:
                code = 404
            else:
                code = 500
            return render_template(f'{str(code)}.html'), code

    return app
from flask import Flask
from config.redis import redis_store
from config.database import db

import config.settings

from modules.ip_blacklist.controllers import ip_bl
from modules.ip_blacklist_api.controllers import api

app = Flask(__name__)
app.config.from_object(config.settings)
redis_store.init_app(app)

db.init_app(app)
app.register_blueprint(ip_bl)
app.register_blueprint(api)

示例#5
0
from routes.web import Route
from config.database import db
from env import *
from flask_session import Session
from flask_bcrypt import Bcrypt
from flask_login import LoginManager

app = Flask(__name__)
login_manager = LoginManager()
sess = Session()
bcrypt = Bcrypt()

app.config['SESSION_TYPE'] = 'filesystem'
app.config['SECRET_KEY'] = 'reds209ndsldssdsljdsldsdsljdsldksdksdsdfsfsfsfis'
app.register_blueprint(Route)

try:
    app.config['SQLALCHEMY_DATABASE_URI'] = "%s://%s:%s@%s/%s" % (
        DB_ENGINE, DB_USERNAME, DB_PASSWORD, DB_HOST, DB_NAME)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # initial
    login_manager.init_app(app)
    db.init_app(app)
    sess.init_app(app)
    bcrypt.init_app(app)

except ValueError as e:
    print(e)

app.run(debug=True)
示例#6
0
from flask import Flask
from config.redis import redis_store
from config.database import db

import config.settings

from modules.ip_blacklist.controllers import ip_bl
from modules.ip_blacklist_api.controllers import api

application = Flask(__name__)
application.config.from_object(config.settings)
redis_store.init_app(application)

db.init_app(application)
application.register_blueprint(ip_bl)
application.register_blueprint(api)