加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

【FLASK】蓝图与session使用Redis缓存

发布时间:2020-12-15 00:31:40 所属栏目:大数据 来源:网络整理
导读:manage.py: from BlueMap.pro_flask import create_appapp = create_app() if __name__ == ' __main__ ' : app.run() ? ?settins.py # debug模式 class DebugSetting(object): DEBUG = True SECRET_KEY = " debug " 测试模式 TesingSetting(object): DEBUG =
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(')

目录结构:

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读