settings.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. """
  2. Django settings for bigdataAPI project.
  3. Generated by 'django-admin startproject' using Django 2.1.4.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/2.1/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/2.1/ref/settings/
  8. """
  9. import os
  10. import datetime
  11. import json
  12. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  13. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  14. # Quick-start development settings - unsuitable for production
  15. # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
  16. # SECURITY WARNING: keep the secret key used in production secret!
  17. SECRET_KEY = '$rs)*w)9gh)nkf1=@r$2xguf1b(qz8ba!%hm8lwt54ti3_da^b'
  18. # SECURITY WARNING: don't run with debug turned on in production!
  19. DEBUG = True
  20. if DEBUG == True:
  21. config_path = os.path.join(BASE_DIR,"test.json")
  22. else:
  23. config_path = os.path.join(BASE_DIR,"formal.json")
  24. with open(config_path,"r") as f:
  25. config_data = f.read()
  26. CONFIG = json.loads(config_data)
  27. ALLOWED_HOSTS = ['*']
  28. # Application definition
  29. INSTALLED_APPS = [
  30. 'django.contrib.admin',
  31. 'django.contrib.auth',
  32. 'django.contrib.contenttypes',
  33. 'django.contrib.sessions',
  34. 'django.contrib.messages',
  35. 'django.contrib.staticfiles',
  36. 'rest_framework',
  37. 'rest_framework_jwt',
  38. 'apps.UserApp',
  39. 'apps.IOTCard',
  40. 'apps.PestAnalysis',
  41. 'apps.Equipment',
  42. ]
  43. MIDDLEWARE = [
  44. 'django.middleware.security.SecurityMiddleware',
  45. 'django.contrib.sessions.middleware.SessionMiddleware',
  46. 'django.middleware.common.CommonMiddleware',
  47. # 'django.middleware.csrf.CsrfViewMiddleware',
  48. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  49. 'django.contrib.messages.middleware.MessageMiddleware',
  50. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  51. ]
  52. ROOT_URLCONF = 'bigdataAPI.urls'
  53. TEMPLATES = [
  54. {
  55. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  56. 'DIRS': [],
  57. 'APP_DIRS': True,
  58. 'OPTIONS': {
  59. 'context_processors': [
  60. 'django.template.context_processors.debug',
  61. 'django.template.context_processors.request',
  62. 'django.contrib.auth.context_processors.auth',
  63. 'django.contrib.messages.context_processors.messages',
  64. ],
  65. },
  66. },
  67. ]
  68. WSGI_APPLICATION = 'bigdataAPI.wsgi.application'
  69. # Database
  70. # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
  71. DATABASES = {
  72. 'default': {
  73. 'ENGINE': 'django.db.backends.mysql',
  74. 'NAME': 'bigdata_api',
  75. 'USER': CONFIG["mysql"]["user"],
  76. 'PASSWORD': CONFIG["mysql"]["pwd"],
  77. 'HOST': CONFIG["mysql"]["host"],
  78. 'PORT': CONFIG["mysql"]["port"],
  79. 'OPTIONS': {'charset': 'utf8mb4'}
  80. }
  81. }
  82. CACHES = {
  83. 'default': {
  84. 'BACKEND': 'django_redis.cache.RedisCache',
  85. "LOCATION": CONFIG["redis"]["url"],
  86. "OPTIONS": {
  87. "CLIENT_CLASS": "django_redis.client.DefaultClient",
  88. }
  89. }
  90. }
  91. # Password validation
  92. # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
  93. AUTH_PASSWORD_VALIDATORS = [
  94. {
  95. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  96. },
  97. {
  98. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  99. },
  100. {
  101. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  102. },
  103. {
  104. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  105. },
  106. ]
  107. # Internationalization
  108. # https://docs.djangoproject.com/en/2.1/topics/i18n/
  109. LANGUAGE_CODE = 'zh-Hans'
  110. TIME_ZONE = 'Asia/Shanghai'
  111. USE_I18N = True
  112. USE_L10N = True
  113. USE_TZ = False
  114. # Static files (CSS, JavaScript, Images)
  115. # https://docs.djangoproject.com/en/2.1/howto/static-files/
  116. STATIC_URL = '/static/'
  117. AUTH_USER_MODEL = 'UserApp.MyUser'
  118. REST_FRAMEWORK = {
  119. # 全局配置异常模块
  120. 'EXCEPTION_HANDLER': 'utils.exception.custom_exception_handler',
  121. # 修改默认返回JSON的renderer的类
  122. 'DEFAULT_RENDERER_CLASSES': (
  123. 'utils.rendererresponse.CustomRender',
  124. ),
  125. 'DEFAULT_THROTTLE_RATES': {
  126. 'devicelist': '100/m',
  127. 'devicedetail': '100/m'
  128. }
  129. }
  130. JWT_AUTH = {
  131. 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
  132. }