提交 c3130ee5 编写于 作者: Amoor123's avatar Amoor123

'20211020session版本'

上级 303b567a
/venv/
/__pycache__/
/sessioncache/
/.idea/
*.log*
/__pycache__/
\ No newline at end of file
from flask import Flask
from flask_session import Session
import settings
app=Flask(__name__)
app.config.from_object(settings.Dev)
\ No newline at end of file
app.config.from_object(settings.Dev)
se=Session()
se.init_app(app)
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>session测试</title>
</head>
<body>
{{ session }}
</body>
</html>
\ No newline at end of file
......@@ -150,3 +150,9 @@ def deletemycookie():
response.delete_cookie('kk',path='/')
return response
from flask import session
@blue.route('/session',methods=['GET','POST'])
def sessiontest():
session['login_user']='amo'
return render_template('session.html',**locals())
# 项目配置文件。一个类就是一套环境
from redis import Redis
class Dev():
ENVIRONMENT='development'
......@@ -9,5 +9,14 @@ class Dev():
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
SQLALCHEMY_ECHO = True
#session的配置
SECRET_KEY='aadasdo*&('
# flask -session 的配置
SESSION_TYPE = 'redis'
SESSION_REDIS = Redis(host='106.14.132.184',port=6377,db=3)
SESSION_FILE_DIR='/sessioncache'
SESSION_FILE_THRESHOLD =3000
SESSION_COOKIE_SECURE = True
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册