Pārlūkot izejas kodu

调整settings配置

yf_fyh 3 gadi atpakaļ
vecāks
revīzija
4867979a49
4 mainītis faili ar 15 papildinājumiem un 15 dzēšanām
  1. 11 11
      bigdataAPI/settings.py
  2. 1 1
      formal.json
  3. 1 1
      test.json
  4. 2 2
      utils/db_utils.py

+ 11 - 11
bigdataAPI/settings.py

@@ -32,7 +32,7 @@ else:
     config_path = "formal.json"
 with open(config_path,"r") as f:
     config_data = f.read()
-config = json.loads(config_data)
+CONFIG = json.loads(config_data)
 
 ALLOWED_HOSTS = ['*']
 
@@ -91,10 +91,10 @@ DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.mysql',
         'NAME': 'bigdata_api',
-        'USER': config["mysql"]["user"],
-        'PASSWORD': config["mysql"]["pwd"],
-        'HOST': config["mysql"]["host"],
-        'PORT': config["mysql"]["port"],
+        'USER': CONFIG["mysql"]["user"],
+        'PASSWORD': CONFIG["mysql"]["pwd"],
+        'HOST': CONFIG["mysql"]["host"],
+        'PORT': CONFIG["mysql"]["port"],
         'OPTIONS': {'charset': 'utf8mb4'}
     }
 }
@@ -102,7 +102,7 @@ DATABASES = {
 CACHES = {
     'default': {
         'BACKEND': 'django_redis.cache.RedisCache',
-        "LOCATION": config["redis"]["url"],
+        "LOCATION": CONFIG["redis"]["url"],
         "OPTIONS": {
             "CLIENT_CLASS": "django_redis.client.DefaultClient",
         }
@@ -149,11 +149,11 @@ AUTH_USER_MODEL = 'UserApp.MyUser'
 
 REST_FRAMEWORK = {
     # 全局配置异常模块
-    'EXCEPTION_HANDLER': 'utils.exception.custom_exception_handler',
-    # 修改默认返回JSON的renderer的类
-    'DEFAULT_RENDERER_CLASSES': (
-        'utils.rendererresponse.CustomRender',
-    ),
+    # 'EXCEPTION_HANDLER': 'utils.exception.custom_exception_handler',
+    # # 修改默认返回JSON的renderer的类
+    # 'DEFAULT_RENDERER_CLASSES': (
+    #     'utils.rendererresponse.CustomRender',
+    # ),
     'DEFAULT_THROTTLE_RATES': {
         'devicelist': '1/m',
         'devicedetail': '1/m'

+ 1 - 1
formal.json

@@ -9,7 +9,7 @@
 		"host": "localhost",
 		"port": "61881",
 		"password": "yf6021",
-        "url": "redis://yf6021@127.0.0.1:61881/12"
+        "url": "redis://:yf6021@127.0.0.1:61881/12"
 	},
 	"bigdatamysql": {
 		"host": "localhost",

+ 1 - 1
test.json

@@ -9,7 +9,7 @@
 		"host": "localhost",
 		"port": "56379",
 		"password": "yf6021",
-        "url": "redis://yf6021@127.0.0.1:56379/12"
+        "url": "redis://:yf6021@127.0.0.1:56379/12"
 	},
 	"bigdatamysql": {
 		"host": "localhost",

+ 2 - 2
utils/db_utils.py

@@ -7,7 +7,7 @@ from django.conf import settings
 
 class MySQLTool:
     def __init__(self):
-        config = settings.config["bigdatamysql"]
+        config = settings.CONFIG["bigdatamysql"]
         self.conn = pymysql.connect(
             host=config['host'], user=config['user'],
             password=config['pwd'], port=config['port'],
@@ -27,7 +27,7 @@ class MySQLTool:
 
 class MongoDBTools:
     def __init__(self, db_name, table_name):
-        config = settings.config["bigdatamongo"]
+        config = settings.CONFIG["bigdatamongo"]
         host, port = config['host'], config['port']
         user, password = config['user'], config['pwd']
         self.client = pymongo.MongoClient(host=host, port=port, username=user, password=password)