manage.py:
from BlueMap.pro_flask import create_app app = create_app() if __name__ == '__main__': app.run()
settins.py
# debug模式 class DebugSetting(object): DEBUG = True SECRET_KEY = "debug" 测试模式 TesingSetting(object): DEBUG =tesing"
__init__.py
from flask Flask from redis Redis from flask_session Session from BlueMap.pro_flask.views login,index from .settings DebugSetting def create_app(): app = Flask(__name__) app.secret_key=1231321w13" app.config.from_object(DebugSetting) 配置redis app.config[SESSION_TYPE'] = redis' session类型为redis app.config[SESSION_REFRESH_EACH_REQUEST'] = True SESSION_PERMANENT'] = False 如果设置为True,则关闭浏览器session就失效。 app.config[SESSION_USE_SIGNER 是否对发送到浏览器上session的cookie值进行加密 app.config[SESSION_KEY_PREFIXsession: 保存到session中的值的前缀 app.config[SESSION_REDIS'] = Redis(host=127.0.0.1',port=6379) Session(app) 导入蓝图 app.register_blueprint(login.ps) app.register_blueprint(index.In) return app
login.py
Blueprint,render_template,session ps = Blueprint(proself) # 蓝图使用 @ps.route(/login",methods=[GETPOST]) login(): session[usernamewanghong" return 登录成功"
index.py
index) # 蓝图使用
@In.route(/index) index(): return session.get(')
目录结构: