settings.py 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. """
  2. Django settings for wtoaamapi project.
  3. Generated by 'django-admin startproject' using Django 4.2.10.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/4.2/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/4.2/ref/settings/
  8. """
  9. import os
  10. from pathlib import Path
  11. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  12. BASE_DIR = Path(__file__).resolve().parent.parent
  13. STATIC_ROOT=BASE_DIR
  14. # Quick-start development settings - unsuitable for production
  15. # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
  16. # SECURITY WARNING: keep the secret key used in production secret!
  17. SECRET_KEY = 'django-insecure-a8dourqo=gfhn(8-@%(v^i*8io86n%(%o4@0qzbm+hhk3!ny@e'
  18. # SECURITY WARNING: don't run with debug turned on in production!
  19. DEBUG = True
  20. # ALLOWED_HOSTS = ['192.168.126.122']
  21. ALLOWED_HOSTS = ['*']
  22. # Application definition
  23. INSTALLED_APPS = [
  24. 'django.contrib.admin',
  25. 'django.contrib.auth',
  26. 'django.contrib.contenttypes',
  27. 'django.contrib.sessions',
  28. 'django.contrib.messages',
  29. 'django.contrib.staticfiles',
  30. 'apps', # 应用名称
  31. 'rest_framework',
  32. 'drf_yasg', # swagger自动生成接口文档
  33. ]
  34. MIDDLEWARE = [
  35. 'django.middleware.security.SecurityMiddleware',
  36. 'django.contrib.sessions.middleware.SessionMiddleware',
  37. 'django.middleware.common.CommonMiddleware',
  38. 'django.middleware.csrf.CsrfViewMiddleware',
  39. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  40. 'django.contrib.messages.middleware.MessageMiddleware',
  41. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  42. # 'middleware.ConcurrencyMiddleware', # 限制所有接口服务的最大请求数
  43. ]
  44. ROOT_URLCONF = 'wtoaamapi.urls'
  45. TEMPLATES = [
  46. {
  47. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  48. 'DIRS': [],
  49. 'APP_DIRS': True,
  50. 'OPTIONS': {
  51. 'context_processors': [
  52. 'django.template.context_processors.debug',
  53. 'django.template.context_processors.request',
  54. 'django.contrib.auth.context_processors.auth',
  55. 'django.contrib.messages.context_processors.messages',
  56. ],
  57. },
  58. },
  59. ]
  60. WSGI_APPLICATION = 'wtoaamapi.wsgi.application'
  61. # Database
  62. # https://docs.djangoproject.com/en/4.2/ref/settings/#databases
  63. DATABASES = {
  64. 'default': {
  65. 'ENGINE': 'django.db.backends.sqlite3',
  66. 'NAME': BASE_DIR / 'db.sqlite3',
  67. 'USER': 'admin',
  68. 'PASSWORD': 'root.123456',
  69. }
  70. }
  71. # DATABASES = {
  72. # 'default': {
  73. # 'ENGINE': 'django.db.backends.mysql',
  74. # 'NAME': 'myapi_db',
  75. # 'USER': 'root',
  76. # 'PASSWORD': 'root',
  77. # 'HOST': '127.0.0.1',
  78. # }
  79. # }
  80. # # 日志配置
  81. # LOGGING = {
  82. # 'version': 1,
  83. # 'disable_existing_loggers': False,
  84. # 'handlers': {
  85. # 'file': {
  86. # 'level': 'DEBUG',
  87. # 'class': 'logging.FileHandler',
  88. # 'filename': os.environ.get('APP_LOG_FILE', r'log/app.log'),
  89. # },
  90. # },
  91. # 'loggers': {
  92. # 'django': {
  93. # 'handlers': ['file'],
  94. # 'level': 'DEBUG',
  95. # 'propagate': True,
  96. # },
  97. # },
  98. # }
  99. # Password validation
  100. # https://docs.djangoproject.com/en/4.2/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/4.2/topics/i18n/
  117. LANGUAGE_CODE = 'en-us'
  118. TIME_ZONE = 'UTC'
  119. USE_I18N = True
  120. USE_TZ = True
  121. # Static files (CSS, JavaScript, Images)
  122. # https://docs.djangoproject.com/en/4.2/howto/static-files/
  123. STATIC_URL = 'static/'
  124. # Default primary key field type
  125. # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
  126. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  127. # 在线swagger文档配置信息
  128. SWAGGER_SETTINGS = {
  129. 'DEFAULT_AUTO_SCHEMA_CLASS': 'config.swagger.CustomSwaggerAutoSchema',
  130. 'VALIDATOR_URL': 'http://localhost:8000',
  131. 'USE_SESSION_AUTH': False,
  132. 'SECURITY_DEFINITIONS': {
  133. 'Token': {
  134. 'type': 'apiKey', #
  135. 'name': 'Authorization',
  136. 'in': 'header'
  137. },
  138. },
  139. }