-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
58 lines (43 loc) · 1.43 KB
/
config.py
File metadata and controls
58 lines (43 loc) · 1.43 KB
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
# -*- coding:utf8 -*-
import os
import json
MY_ROOT_DIR = os.path.abspath(os.path.dirname(__file__))
class ReadConfigJson(object):
@staticmethod
def __read_db_json():
db_config = os.path.join(MY_ROOT_DIR, 'config.json')
with open(db_config, encoding='utf-8') as f:
data = f.read()
data = json.loads(data)
return data
def get_mysql_config(self):
mysql_dict = self.__read_db_json()['mysql']
mysql_url = 'mysql+pymysql://{user}:{password}@{host}:{port}/{database}?charset=utf8'.format(
user=mysql_dict['user'],
password=mysql_dict['password'],
host=mysql_dict['host'],
port=mysql_dict['port'],
database=mysql_dict['database'])
return mysql_url
@staticmethod
def get_sqlite_config():
sqlite_db_dir = os.path.join(MY_ROOT_DIR, 'db')
try:
os.makedirs(sqlite_db_dir)
except:
pass
return 'sqlite:///{}'.format(os.path.join(sqlite_db_dir, 'data.db'))
class Config:
DEBUG = True
# SECRET_KEY = os.urandom(24)
SECRET_KEY = 'tc'
SQLALCHEMY_DATABASE_URI = ReadConfigJson.get_sqlite_config()
SQLALCHEMY_COMMIT_ON_TEARDOWN = True
SQLALCHEMY_TRACK_MODIFICATIONS = False
SQLALCHEMY_ECHO = False
BOOTSTRAP_SERVE_LOCAL = True
FLASKY_PER_PAGE = 20
ASSETS_DEBUG = False
@staticmethod
def init_app(app):
pass