Skip to content

Commit

Permalink
session储存位置指定和测试
Browse files Browse the repository at this point in the history
  • Loading branch information
zhushixia committed Aug 16, 2018
1 parent 66c3da1 commit 9ee479c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions manager.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
from flask import Flask
import redis
from flask import Flask,session
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.wtf import CSRFProtect
from redis import StrictRedis

from flask_session import Session#可以指定session保存到位置

class Config(object):#项目的配置
DEBUG = True
SECRET_KEY = "LzUA6O2R2R/mNSD6cbQ5Fzqkq+5VUa3B9/42IG9uoVSzRFbqf2Q6ZGUSVNa4JDstGSADO7hEsQhwk6papcOs4g=="
#为数据库添加配置
SQLAlchemy_DATABASE_URI = "mysql://root:[email protected]:3306/information27"
SQLALCHEMY_TRACK_MODIFICATIONS = False
#Redis的配置
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 的有效期,单位是秒
SESSION_PERMANENT = False

app = Flask(__name__)
#加载配置
Expand All @@ -23,11 +31,13 @@ class Config(object):#项目的配置
redis_store = StrictRedis(host=Config.REDIS_HOST, port=Config.REDIS_PORT)
#开启当前项目csrf保护,只做服务验证工作
CSRFProtect(app)
Session(app)



@app.route("/")
def index():
session["name"] = "itheima"
return "index112e111"

if __name__ == "__main__":
Expand Down

0 comments on commit 9ee479c

Please sign in to comment.