This repository has been archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
49 lines (40 loc) · 1.91 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# coding: utf-8
#
# Created by dylanchu on 19-2-15
import hashlib
from datetime import timedelta
class BaseConfig(object):
LOG_LEVEL = 'DEBUG' # DEBUG, INFO, WARNING, ERROR, CRITICAL. 可使用app.logger.exception(msg),但level没有EXCEPTION
SECRET_KEY = 'dL28o(19xi54h2?3BX90k92R' # 为安全推荐从环境变量获取
# session
SESSION_TYPE = 'null' # null(采用flask默认的保存在cookie中),可为redis/memcached等
SESSION_USE_SIGNER = True # 是否强制加盐混淆session
SESSION_PERMANENT = True # 是否长期有效,false则关闭浏览器失效
PERMANENT_SESSION_LIFETIME = 7200 # 重要,session有效期(秒),默认永久有效
REMEMBER_COOKIE_DURATION = timedelta(days=3)
# mongoengine, https://flask-mongoengine.readthedocs.io/en/latest/
MONGODB_SETTINGS = {
'db': 'usmt',
'host': '172.19.240.16',
'port': 27017,
# if authentication is needed:
# 'username': 'webapp',
# 'password': 'pwd123',
'connect': False # False: connect when first connect instead of instantiated
}
# 自定义
@staticmethod
def MD5_HASH(password) -> str:
_MD5_SALT = 'a random string'
_MD5_TOOL = hashlib.md5()
_MD5_TOOL.update((password + _MD5_SALT).encode())
return _MD5_TOOL.hexdigest()
class DevelopmentConfig(BaseConfig):
import os
SECRET_KEY = os.urandom(24) # 设为24位的随机字符,重启服务器则上次session清除
WTF_CSRF_ENABLED = False # 是否开启flask-wtf的csrf保护,默认是True,用postman提交表单测试需要设为False
# from redis import Redis
# SESSION_TYPE = 'redis' # null(采用flask默认的保存在cookie中) / redis / memcached / ..
# SESSION_REDIS = Redis(host='127.0.0.1', port=6379, db=0, password=None)
# SESSION_KEY_PREFIX = 'flask_session:' # session的redis等键名前缀,默认为'session:'