-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
75 lines (64 loc) · 2.03 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
获取配置
"""
import os
import dotenv
env_path = os.path.join(os.path.dirname(__file__), ".env")
dotenv.load_dotenv(env_path)
class BasicConfig:
# mysql
MYSQL_ADDRESS = os.environ.get("MYSQL_ADDRESS", "127.0.0.1")
MYSQL_PORT = int(os.environ.get("MYSQL_PORT", 3306))
MYSQL_DATABASE = os.environ.get("MYSQL_DATABASE", "flask_app")
MYSQL_DATABASE_TEST = os.environ.get("MYSQL_DATABASE", "flask_app_test")
MYSQL_USER = os.environ.get("MYSQL_USER", "flask_app")
MYSQL_PASSWORD = os.environ.get("MYSQL_PASSWORD", "password")
# sqlalchemy
SQLALCHEMY_DATABASE_URI = (
"mysql://"
+ MYSQL_USER
+ ":"
+ MYSQL_PASSWORD
+ "@"
+ MYSQL_ADDRESS
+ ":"
+ str(MYSQL_PORT)
+ "/"
+ MYSQL_DATABASE
)
SQLALCHEMY_DATABASE_URI_TEST = (
"mysql://"
+ MYSQL_USER
+ ":"
+ MYSQL_PASSWORD
+ "@"
+ MYSQL_ADDRESS
+ ":"
+ str(MYSQL_PORT)
+ "/"
+ MYSQL_DATABASE_TEST
)
SQLALCHEMY_TRACK_MODIFICATIONS = False
# redis
REDIS_ADDRESS = os.environ.get("REDIS_ADDRESS", "127.0.0.1")
REDIS_PORT = os.environ.get("REDIS_PORT", 6379)
REDIS_URL = os.environ.get(
"REDIS_URL", "redis://" + REDIS_ADDRESS + ":" + str(REDIS_PORT)
)
# swagger
SWAGGER_TITLE = "New Flask App"
# email
MAIL_SERVER = os.environ.get("MAIL_SERVER", "smtp.qq.com")
MAIL_PORT = int(os.environ.get("MAIL_PORT", 465))
MAIL_USE_SSL = bool(os.environ.get("MAIL_USE_SSL", True))
MAIL_USE_TLS = bool(os.environ.get("MAIL_USE_TLS", False))
MAIL_USERNAME = os.environ.get("MAIL_USERNAME", "")
MAIL_PASSWORD = os.environ.get("MAIL_PASSWORD", "")
MAIL_DEFAULT_SENDER = os.environ.get("MAIL_DEFAULT_SENDER", MAIL_USERNAME)
# 服务器
HTTP_HOST = "127.0.0.1"
HTTP_PORT = 5000
# 其它
SECRET_KEY = os.environ.get("SECRET_KEY", "flask_app")
TOKEN_EXPIRATION = int(os.environ.get("EXPIRATION", 60 * 60 * 24 * 30))
config = BasicConfig()