def create_app(): BASE_DIR = os.path.dirname(os.path.dirname(__file__)) static_dir = os.path.join(BASE_DIR, 'static') templates_dir = os.path.join(BASE_DIR, 'templates') app = Flask(__name__, static_folder=static_dir, template_folder=templates_dir) app.register_blueprint(blueprint=user, url_prefix='/user') app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/flask6' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # 设置session密钥 app.config['SECRET_KEY'] = 'secret_key' db.init_app(app=app) # with app.app_context(): # db.drop_all() # db.create_all() return app
def create_app(): app = Flask(__name__) app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:1234@localhost:3306/SQL-ALCHEMY' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app=app) return app
def create_app(): # 定义系统路径,当前文件目录 BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # 定义静态文件路径 static_dir = os.path.join(BASE_DIR, 'static') # 定义模板目录 templates_dir = os.path.join(BASE_DIR, 'templates') # 初始化app app = Flask(__name__, static_folder=static_dir, template_folder=templates_dir) # 注册蓝图 app.register_blueprint(blueprint=user_bp, url_prefix='/user') # 配置数据库 app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/sms' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # 设置session秘钥,用于和session内容生成hash值,防止内容被串改 app.config['SECRET_KEY'] = 'secret_key' # 设置session存储库, 使用redis app.config['SESSION_TYPE'] = 'redis' # 连接redis app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1', port=6379, db=1) # 初始化db db.init_app(app=app) return app
def create_app(): # 定义系统路径的变量 BASE_DIR = os.path.dirname(os.path.dirname(__file__)) # 定义静态文件的路径 static_dir = os.path.join(BASE_DIR, 'static') # 定义模板文件的路径 templates_dir = os.path.join(BASE_DIR, 'templates') # 初始化app 和manage.py文件关联 app = Flask(__name__, static_folder=static_dir, template_folder=templates_dir) # 注册蓝图 app.register_blueprint(blueprint=user_blueprint, url_prefix='/user') app.register_blueprint(blueprint=main, url_prefix='/') app.register_blueprint(blueprint=tools, url_prefix='/tools') # 配置mysql数据库 app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://ksrong-ops:[email protected]:3306/ksrong-ops?charset=utf8mb4' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # 设置session密钥 app.config['SECRET_KEY'] = 'sdertyuhgfd23456q' # 设置连接的redis数据库 默认连接到本地6379 app.config['SESSION_TYPE'] = 'redis' # 设置远程 app.config['SESSION_REDIS'] = redis.Redis(host='redis.ksrong-ops.com', port=6379, password='******') # 初始化db db.init_app(app=app) return app
def ext_init(app): # Session(app=app) se.init_app(app=app) db.init_app(app=app) toolbar.init_app(app=app) api.init_app(app=app)
def init_ext(app): app.register_blueprint(blueprint=blue) app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost:3306/linzhen' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app=app) migrate.init_app(app=app, db=db)
def create_app(): BASE_DIR = os.path.dirname(os.path.dirname(__file__)) #print(BASE_DIR) static_dir = os.path.join(BASE_DIR, 'static') templates_dir = os.path.join(BASE_DIR, 'templates') app = Flask(__name__, static_folder=static_dir, template_folder=templates_dir) app.register_blueprint(blueprint=user_blueprint, url_prefix='/user') app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///testdb.db' #'mysql+pymysql://root:[email protected]:3306/Htai' # print(app.config['SQLALCHEMY_DATABASE_URI']) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # 设置session密钥 app.config['SECRET_KEY'] = 'secret_key' # 设置连接的redis数据库 默认连接到本地6379 app.config['SESSION_TYPE'] = 'redis' # 设置远程 app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1', port=6379) db.init_app(app=app) return app
def init_app(): app = Flask(__name__) DB_URI = 'sqlite:///sqlite3.db' DIALECT = 'mysql' DRIVER = 'pymysql' HOSTNAME = 'localhost' PORT = '3306' DATABASE = 'flaskdb' USERNAME = '******' PASSWORD = '******' SQLALCHEMY_DATABASE_URI = '{}+{}://{}:{}@{}:{}/{}?charset=utf8'.format(DIALECT, DRIVER, USERNAME, PASSWORD, HOSTNAME, PORT, DATABASE) #配置数据库 app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False #初始化orm db.init_app(app=app) #初始化蓝图 init_blue(app) return app
def create_app(): BASE_DIR = os.path.dirname(os.path.dirname(__file__)) static_dir = os.path.join(BASE_DIR, 'static') templates_dir = os.path.join(BASE_DIR, 'templates') app = Flask(__name__, static_folder=static_dir, template_folder=templates_dir) app.register_blueprint(blueprint=admin, url_prefix='/user') app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/flaskstudent' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # 如果设置成True(默认情况),Flask-SQLAlchemy 将会追踪对象的修改并且发送信号。这需要额外的内存, 如果不必要的可以禁用它 # 设置session密钥 app.config['SECRET_KEY'] = 'secret_key' db.init_app(app=app) with app.app_context(): # db.drop_all() db.create_all() return app
def create_app(): #定义系统路径的变量 BASE_DIR = os.path.dirname(os.path.dirname(__file__)) #定义静态文件的路径 static_dir = os.path.join(BASE_DIR, 'static') #定义模版文件的路径 templates_dir = os.path.join(BASE_DIR, 'templates') #初始化app和manage.py文件关联 app = Flask(__name__, static_folder=static_dir, template_folder=templates_dir) #注册蓝图 app.register_blueprint(blueprint=user_blueprint, url_prefix='/user') #配置MySQL数据库 app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/Htai' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False #设置session钥匙 app.config['SECRET_KEY'] = 'secret_key' #设置连接的Redis数据库,默认连接到本地6379 app.config['SESSION_TYPE'] = 'redis' #设置远程 app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1', port=6379) #初始化db db.init_app(app=app) return app
def create_app(): BASE_DIR = os.path.dirname(os.path.dirname(__file__)) static_dir = os.path.join(BASE_DIR, 'static') templates_dir = os.path.join(BASE_DIR, 'templates') app = Flask(__name__, static_folder=static_dir, template_folder=templates_dir) # 注册蓝图 app.register_blueprint(blueprint=hello_blueprint, url_prefix='/hello') app.register_blueprint(blueprint=user_blueprint, url_prefix='/user') # 配置数据库 app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/helloflask' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # 设置session密钥 app.config['SECRET_KEY'] = 'secret_key' # 设置连接的redis数据库 默认连接到本地6379 app.config['SESSION_TYPE'] = 'redis' # 设置远程 app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1', port=6379) # 初始化session # 第一种 # se = Session() # se.init_app(app=app) # 第二种 Session(app=app) # 初始化模型 # 第一种方法 db.init_app(app=app) return app
def create_app(): BASE_DIR = os.path.dirname(os.path.dirname(__file__)) static_dir = os.path.join(BASE_DIR, 'static') templates_dir = os.path.join(BASE_DIR, 'templates') app = Flask(__name__, static_folder=static_dir, template_folder=templates_dir) app.register_blueprint(blueprint=hello_blueprint, url_prefix='/hello') app.register_blueprint(blueprint=user_blueprint, url_prefix='/user') # 秘钥 app.config['SECRET_KEY'] = 'secret_key' # session类型 app.config['SESSION_TYPE'] = 'redis' # redis ip和端口,默认127.0.0.1:6379 app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1', port=6379) # 配置数据库 app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost:3306/db_flask' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # 第一种 # sess = Session() # sess.init_app(app=app) # 第二种 Session(app=app) db.init_app(app=app) return app
def init_ext(app): app.config['SECRET_KEY'] = '110' Session(app=app) app.register_blueprint(blueprint=blue) db.init_app(app=app) migrate = Migrate() migrate.init_app(app=app,db=db)
def init_ext(app): # session app.config['SECRET_KEY'] = '119' app.config['SESSION_TYPE'] = 'redis' app.config['SESSION_KEY_PREFIX'] = 'python1905' Session(app=app) # sqlalchemy db.init_app(app=app) # migrate migrate = Migrate() migrate.init_app(app=app, db=db) # flask-bootstrap Bootstrap(app=app) # flask-debugtoolbar # app.debug = True # debugtoolbar = DebugToolbarExtension() # debugtoolbar.init_app(app=app) # flask-cache # 如果cache在方法内 那么导包是不可以的 需要将这个遍历防到方法外 # cache = Cache(config={'CACHE_TYPE':'redis'}) # 如果报错 ImportError: No module named 'flask.ext' # 解决方法:(1)打开site-packages # (2) flask-cache下的jinja2ext.py # (3) 修改from flask.ext.cache import make_template_fragment_key为 # from flask_cache import make_template_fragment_key cache.init_app(app=app)
def create_app(): static_dir = os.path.join(BASE_DIR, 'static') templates_dir = os.path.join(BASE_DIR, 'templates') app = Flask(__name__, static_folder=static_dir, template_folder=templates_dir) app.register_blueprint(blueprint=user_blueprint, url_prefix='/user') app.register_blueprint(blueprint=house_blueprint, url_prefix='/house') app.register_blueprint(blueprint=order_blueprint, url_prefix='/order') app.config[ 'SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://root:123456@localhost:3306/aj01" app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SECRET_KEY'] = 'secret_key' app.config['SESSION_TYPE'] = 'redis' app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1', port=6379) db.init_app(app=app) se.init_app(app=app) return app
def create_app(): app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db' app.config['SECRET_KEY'] = "MYSECRET" app.config['JWT_EXPIRATION_DELTA'] = timedelta(days=7) db.init_app(app) return app
def init_ext(app, name): app.register_blueprint(blueprint=blue) # de = DebugToolbarExtension() # de.init_app(app=app) Session(app=app) db.init_app(app=app) Migrate(db=db, app=app) Bootstrap(app=app)
def create_app(): app = Flask(__name__) app.config[ "SQLALCHEMY_DATABASE_URI"] = 'mysql+pymysql://ccq:[email protected]:3306/day03flask' #第一次出现错误:SQLALCHEMY_TRACK_MODIFICATIONS ,那么配置,使其关闭 app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app=app) return app
def create_app(): app = Flask(__name__,template_folder='../templates') app.register_blueprint(blueprint=blue) app.config['SECRET_KEY']='sgtsrhystjsfrhdhe' #test.db是相对于App下的路径 app.config['SQLALCHEMY_DATABASE_URI']='sqlite:///test.db' db.init_app(app=app) return app
def create_app(): app = Flask(__name__) # dialect(方言)+drive(驱动)://username:password@host:port/database app.config[ 'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://lwq:123123@localhost:3306/day031905' # app.config['sqlalchemy_database_uri'] = 'mysql+pymysql://lwq:123123@localhost:3306/day031905' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # app.config['sqlalchemy_track_modifications']=False db.init_app(app=app) return app
def init_ext(app): app.config['SECRET_KEY'] = '110' app.config['SESSION_TYPE'] = 'redis' app.config['SESSION_KEY_PREFIX'] = 'empmanager' Session(app=app) db.init_app(app=app) migrate = Migrate() migrate.init_app(app=app, db=db)
def init_extends(app): app.config['secret_key'] = '12306' app.config['session_type'] = 'redis' Session(app=app) # app.config['sqlalchemy_database_uri'] = 'mysql+pymysql://qmx:123@localhost:3306/exercise' # app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app=app) migrate = Migrate() migrate.init_app(app=app, db=db)
def init_ext(app): # 命令行参数使用 migrate = Migrate() migrate.init_app(app=app, db=db) # 数据库初始化 db.init_app(app=app) # cache初始化 cache.init_app(app=app) #邮箱邮箱初始化 mail.init_app(app=app)
def init_app(app): #sqlalchemy 模型 db.init_app(app=app) #falsk_migrate 模型迁移 migrate = Migrate() #创建模型迁移对象 migrate.init_app(app=app, db=db) #模型迁移肯定需要模型的 #初始化cache cache.init_app(app=app)
def create_app(): app = Flask(__name__, static_url_path='/static') loadConfig(app) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['TEMPLATES_AUTO_RELOAD'] = True app.config['PREFERRED_URL_SCHEME'] = 'https' app.config['UPLOADED_PHOTOS_DEST'] = "App/uploads" photos = UploadSet('photos', TEXT + DOCUMENTS + IMAGES) configure_uploads(app, photos) db.init_app(app) return app
def create_app(config={}): app = Flask(__name__) app.config.from_object('App.config_dev') app.config.update(config) db.init_app(app) register_all_views(app) login_manager.init_app(app) app.before_request(before_request) return app
def init_extendtion(app): db.init_app(app=app) session_key = 'secret_key' session_type = 'session_type' app.config[session_key.upper()] = '12306' app.config[session_type.upper()] = 'redis' Session(app=app) migrate =Migrate() migrate.init_app(app=app,db=db)
def init_ext(app): # blue # app.register_blueprint(blueprint=blue) # migrate migrate = Migrate() migrate.init_app(app=app, db=db) # session app.config['SECRET_KEY'] = '100' app.config['SESSION_TYPE'] = 'redis' api = Api(app) api.add_resource(Hello, '/') Session(app=app) # sqlalchemy db.init_app(app=app)
def init_app(app): #flask_session app.config['SECRET_KEY'] = '110' app.config['SESSION_TYPE'] = 'redis' app.config['SESSION_KEY_PREFIX'] = 'day05flask' Session(app=app) #sqlalchemy 模型 db.init_app(app=app) #falsk_migrate 模型迁移 migrate = Migrate() #创建模型迁移对象 migrate.init_app(app=app, db=db) #模型迁移肯定需要模型的
def init_ext(app): app.config['SECRET_KEY'] = 'xiong' app.config['SESSION_TYPE'] = 'redis' app.config['SESSION_KEY_PREFIX'] = 'python' Session(app=app) # sqlalchemy app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:1234@localhost:3306/SQL-ALCHEMY' db.init_app(app=app) # flask-migrate migrate = Migrate() migrate.init_app(db=db,app=app)
def init_ext(app): # flask-session app.config['SESSION_KEY'] = '110' app.config['SESSION_TYPE'] = 'redis' app.config['SESSION_KEY_PREFIX'] = 'python1905' Session(app=app) # flask-sqlalchemy # app.config['SQLALCHEMY_TRACK_MODIFICAITIONS'] = False # app.comfig['SQLACHEMY_DATABASE_URI'] = 'mysql+pymysql://ccq:123@localhost:3306/day04flask' db.init_app(app=app) #flask-migrate,先创建对象,然后初始化,参数app与db,讲app与模型传给migrate migrate = Migrate() migrate.init_app(app=app, db=db)