settings.py 4.5 KB

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