-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhushixia
committed
Aug 16, 2018
1 parent
66c3da1
commit 9ee479c
Showing
2 changed files
with
13 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) | ||
#加载配置 | ||
|
@@ -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__": | ||
|