コード例 #1
0
def create_user_roles():
    db.drop_all()
    try:
        db.create_all()
        role_1 = user_datastore.create_role(name='userrank',chname=u'用户排名' ,description=u'用户排行模块权限')


        user_1 = user_datastore.create_user(email='*****@*****.**', password="******")

        user_datastore.add_role_to_user(user_1, role_1)

        db.session.commit()
        return "success"
    except:
        db.session.rollback()
        return "failure"
コード例 #2
0
def create_user_roles():
    db.drop_all()
    try:
        db.create_all()
        role_1 = user_datastore.create_role(name='userrank',
                                            chname=u'用户排名',
                                            description=u'用户排行模块权限')

        user_1 = user_datastore.create_user(email='*****@*****.**',
                                            password="******")

        user_datastore.add_role_to_user(user_1, role_1)

        db.session.commit()
        return "success"
    except:
        db.session.rollback()
        return "failure"
コード例 #3
0
def create_app():
    app = Flask(__name__)
    #下面这一句新加的
    app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///flask-admin.db'
    register_blueprints(app)
    register_extensions(app)
    register_jinja_funcs(app)

    # Create modules

    # the debug toolbar is only enabled in debug mode
    app.config['DEBUG'] = True

    app.config['ADMINS'] = frozenset(['*****@*****.**'])
    app.config['SECRET_KEY'] = 'SecretKeyForSessionSigning'
    '''
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqldb://%s:@%s/%s?charset=utf8' % (MYSQL_USER, MYSQL_HOST, MYSQL_DB)
    app.config['SQLALCHEMY_ECHO'] = False
    '''
    app.config['DATABASE_CONNECT_OPTIONS'] = {}

    app.config['THREADS_PER_PAGE'] = 8

    app.config['CSRF_ENABLED'] = True
    app.config['CSRF_SESSION_KEY'] = 'somethingimpossibletoguess'

    # Enable the toolbar?
    app.config['DEBUG_TB_ENABLED'] = app.debug
    # Should intercept redirects?
    app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = True
    # Enable the profiler on all requests, default to false
    app.config['DEBUG_TB_PROFILER_ENABLED'] = True
    # Enable the template editor, default to false
    app.config['DEBUG_TB_TEMPLATE_EDITOR_ENABLED'] = True

    # debug toolbar
    # toolbar = DebugToolbarExtension(app)
    #新加的app.config到return之前
    app.config['MONGO_HOST'] = '219.224.134.211'
    app.config['MONGO_PORT'] = 27017
    app.config['MONGO_DBNAME'] = 'mrq'
    # init database
    db.init_app(app)
    with app.test_request_context():
        db.create_all()

    # init security
    security.init_app(app, datastore=user_datastore)

    # init admin
    admin.init_app(app)
    #admin.add_view(AdminAccessView(User, db.session))
    #admin.add_view(AdminAccessView(Role, db.session))
    #admin.add_view(sqla.ModelView(User, db.session))
    #admin.add_view(sqla.ModelView(Role, db.session))
    #admin.add_view(Roleadmin(db.session))

    # init mongo
    mongo.init_app(app)

    return app
コード例 #4
0
def create_app():
    app = Flask(__name__)
    #下面这一句新加的
    app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///flask-admin.db'
    register_blueprints(app)
    register_extensions(app)
    register_jinja_funcs(app)

    # Create modules

    # the debug toolbar is only enabled in debug mode
    app.config['DEBUG'] = True

    app.config['ADMINS'] = frozenset(['*****@*****.**'])
    app.config['SECRET_KEY'] = 'SecretKeyForSessionSigning'
    
    '''
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqldb://%s:@%s/%s?charset=utf8' % (MYSQL_USER, MYSQL_HOST, MYSQL_DB)
    app.config['SQLALCHEMY_ECHO'] = False
    '''
    app.config['DATABASE_CONNECT_OPTIONS'] = {}

    app.config['THREADS_PER_PAGE'] = 8

    app.config['CSRF_ENABLED'] = True
    app.config['CSRF_SESSION_KEY'] = 'somethingimpossibletoguess'

    # Enable the toolbar?
    app.config['DEBUG_TB_ENABLED'] = app.debug
    # Should intercept redirects?
    app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = True
    # Enable the profiler on all requests, default to false
    app.config['DEBUG_TB_PROFILER_ENABLED'] = True
    # Enable the template editor, default to false
    app.config['DEBUG_TB_TEMPLATE_EDITOR_ENABLED'] = True
    
    # debug toolbar
    # toolbar = DebugToolbarExtension(app)
#新加的app.config到return之前
    app.config['MONGO_HOST'] = '219.224.134.211'    
    app.config['MONGO_PORT'] = 27017    
    app.config['MONGO_DBNAME'] = 'mrq'   
     # init database
    db.init_app(app)
    with app.test_request_context():
        db.create_all()

    # init security
    security.init_app(app, datastore=user_datastore)

    # init admin
    admin.init_app(app)
    #admin.add_view(AdminAccessView(User, db.session))
    #admin.add_view(AdminAccessView(Role, db.session))
    #admin.add_view(sqla.ModelView(User, db.session))
    #admin.add_view(sqla.ModelView(Role, db.session))
    #admin.add_view(Roleadmin(db.session))

    # init mongo
    mongo.init_app(app)         

    return app