# manage.py 文件
from flask_script import Manager
from flask_migrate import Migrate,MigrateCommand
from .info import app,db
manager = Manager(app)
# 用于数据库迁移
Migrate(app, db)
manager.add_command(‘db‘,MigrateCommand)
if __name__ == ‘__main__‘:
# app.run()
manager.run()
# info包,__init__.py文件
import redis
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import CSRFProtect
from flask_session import Session
from config import MyConfig
app= Flask(__name__)
db = SQLAlchemy(app)
app.config.from_object(MyConfig)
# 开启csrf保护
CSRFProtect(app)
# 配置redis
redis_store = redis.StrictRedis(host=MyConfig.REDIS_HOST, port=MyConfig.REDIS_PORT)
# 配置Session
Session(app)
# config.py文件
import redis
class MyConfig(object):
DEBUG = True
# 配置SECRET_KEY
SECRET_KEY = "EjpNVSNQTyGi1VvWECj9TvC/+kq3oujee2kTfQUs8yCM6xX9Yjq52v54g+HVoknA"
# 数据库的配置信息
SQLALCHEMY_DATABASE_URI = "mysql://root:[email protected]:3306/flask_job_project"
SQLALCHEMY_TRACK_MODIFICATIONS = False
# 配置常量
REDIS_HOST = ‘127.0.0.1‘
REDIS_PORT = 6379
# flask_session的配置信息
SESSION_TYPE = "redis" # 指定 session 保存到 redis 中
SESSION_USE_SIGNER = True # 让 cookie 中的 session_id 被加密签名处理
SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT)
# 使用 redis 的实例
PERMANENT_SESSION_LIFETIME = 86400 # session 的有效期,单位是秒
原文地址:http://blog.51cto.com/13914991/2171443
时间: 2024-10-17 07:11:27