settings.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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:
  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. CORS_ORIGIN_ALLOW_ALL = True
  29. CORS_ALLOW_CREDENTIALS = True
  30. CORS_ALLOW_ALL_ORIGINS = True
  31. # Application definition
  32. INSTALLED_APPS = [
  33. 'corsheaders',
  34. 'django.contrib.admin',
  35. 'django.contrib.auth',
  36. 'django.contrib.contenttypes',
  37. 'django.contrib.sessions',
  38. 'django.contrib.messages',
  39. 'django.contrib.staticfiles',
  40. 'rest_framework',
  41. 'rest_framework_jwt',
  42. 'apps.UserApp',
  43. 'apps.IOTCard',
  44. 'apps.PestAnalysis',
  45. 'apps.Equipment',
  46. 'apps.QxzApp',
  47. 'apps.Weather',
  48. 'apps.DeviceCount'
  49. ]
  50. MIDDLEWARE = [
  51. 'django.middleware.security.SecurityMiddleware',
  52. 'django.contrib.sessions.middleware.SessionMiddleware',
  53. 'corsheaders.middleware.CorsMiddleware',
  54. 'django.middleware.common.CommonMiddleware',
  55. # 'django.middleware.csrf.CsrfViewMiddleware',
  56. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  57. 'django.contrib.messages.middleware.MessageMiddleware',
  58. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  59. ]
  60. ROOT_URLCONF = 'bigdataAPI.urls'
  61. TEMPLATES = [
  62. {
  63. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  64. 'DIRS': [],
  65. 'APP_DIRS': True,
  66. 'OPTIONS': {
  67. 'context_processors': [
  68. 'django.template.context_processors.debug',
  69. 'django.template.context_processors.request',
  70. 'django.contrib.auth.context_processors.auth',
  71. 'django.contrib.messages.context_processors.messages',
  72. ],
  73. },
  74. },
  75. ]
  76. WSGI_APPLICATION = 'bigdataAPI.wsgi.application'
  77. # Database
  78. # https://docs.djangoproject.com/en/2.1/ref/settings/#databases
  79. DATABASES = {
  80. 'default': {
  81. 'ENGINE': 'django.db.backends.mysql',
  82. 'NAME': 'bigdata_api',
  83. 'USER': CONFIG["mysql"]["user"],
  84. 'PASSWORD': CONFIG["mysql"]["pwd"],
  85. 'HOST': CONFIG["mysql"]["host"],
  86. 'PORT': CONFIG["mysql"]["port"],
  87. 'OPTIONS': {'charset': 'utf8mb4'}
  88. }
  89. }
  90. CACHES = {
  91. 'default': {
  92. 'BACKEND': 'django_redis.cache.RedisCache',
  93. "LOCATION": CONFIG["redis"]["url"],
  94. "OPTIONS": {
  95. "CLIENT_CLASS": "django_redis.client.DefaultClient",
  96. }
  97. }
  98. }
  99. # Password validation
  100. # https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
  101. AUTH_PASSWORD_VALIDATORS = [
  102. {
  103. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  104. },
  105. {
  106. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  107. },
  108. {
  109. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  110. },
  111. {
  112. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  113. },
  114. ]
  115. # Internationalization
  116. # https://docs.djangoproject.com/en/2.1/topics/i18n/
  117. LANGUAGE_CODE = 'zh-Hans'
  118. TIME_ZONE = 'Asia/Shanghai'
  119. USE_I18N = True
  120. USE_L10N = True
  121. USE_TZ = False
  122. # Static files (CSS, JavaScript, Images)
  123. # https://docs.djangoproject.com/en/2.1/howto/static-files/
  124. STATIC_URL = '/static/'
  125. STATIC_ROOT = os.path.join(BASE_DIR, 'static')
  126. AUTH_USER_MODEL = 'UserApp.MyUser'
  127. REST_FRAMEWORK = {
  128. # 全局配置异常模块
  129. 'EXCEPTION_HANDLER': 'utils.exception.custom_exception_handler',
  130. # 修改默认返回JSON的renderer的类
  131. 'DEFAULT_RENDERER_CLASSES': (
  132. 'utils.rendererresponse.CustomRender',
  133. ),
  134. 'DEFAULT_THROTTLE_RATES': {
  135. 'devicelist': '100/m',
  136. 'devicedetail': '100/m'
  137. }
  138. }
  139. JWT_AUTH = {
  140. 'JWT_EXPIRATION_DELTA': datetime.timedelta(days=1),
  141. }