settings.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. """
  2. Django settings for monitor project.
  3. Generated by 'django-admin startproject' using Django 2.2.27.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/2.2/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/2.2/ref/settings/
  8. """
  9. import os
  10. from loguru import logger
  11. # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
  12. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  13. log_file = os.path.join(BASE_DIR, 'log/django_error.log')
  14. # 一个地方配置后,全局都可以from loguru import logger 导入使用
  15. logger.add(
  16. log_file,
  17. level='DEBUG',
  18. format='{time:YYYY-MM-DD HH:mm:ss} {level} {file}[line:{line}] {message}',
  19. rotation="00:00",
  20. retention='10 days',
  21. encoding="utf-8",
  22. compression='tar.gz',
  23. diagnose=True,
  24. backtrace=True,
  25. enqueue=True
  26. )
  27. # Quick-start development settings - unsuitable for production
  28. # See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
  29. # SECURITY WARNING: keep the secret key used in production secret!
  30. SECRET_KEY = 'c2pfrk2se(9slc%1o=+k)2ukd9q5$8fqwq4cysu*o-$j=nzvd*'
  31. # SECURITY WARNING: don't run with debug turned on in production!
  32. DEBUG = True
  33. ALLOWED_HOSTS = ['*']
  34. APPEND_SLASH = False
  35. # Application definition
  36. INSTALLED_APPS = [
  37. 'django.contrib.admin',
  38. 'django.contrib.auth',
  39. 'django.contrib.contenttypes',
  40. 'django.contrib.sessions',
  41. 'django.contrib.messages',
  42. 'django.contrib.staticfiles',
  43. 'rest_framework',
  44. 'drf_yasg',
  45. 'drf_spectacular',
  46. 'monitor_app'
  47. ]
  48. MIDDLEWARE = [
  49. 'django.middleware.security.SecurityMiddleware',
  50. 'django.contrib.sessions.middleware.SessionMiddleware',
  51. 'django.middleware.common.CommonMiddleware',
  52. 'django.middleware.csrf.CsrfViewMiddleware',
  53. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  54. 'django.contrib.messages.middleware.MessageMiddleware',
  55. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  56. 'monitor.middleware.ExceptionGlobeMiddleware'
  57. ]
  58. REST_FRAMEWORK = {
  59. # YOUR SETTINGS
  60. 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
  61. 'DEFAULT_PAGINATION_CLASS': 'monitor.pagination.CustomPagination',
  62. }
  63. ROOT_URLCONF = 'monitor.urls'
  64. TEMPLATES = [
  65. {
  66. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  67. 'DIRS': [],
  68. 'APP_DIRS': True,
  69. 'OPTIONS': {
  70. 'context_processors': [
  71. 'django.template.context_processors.debug',
  72. 'django.template.context_processors.request',
  73. 'django.contrib.auth.context_processors.auth',
  74. 'django.contrib.messages.context_processors.messages',
  75. ],
  76. },
  77. },
  78. ]
  79. WSGI_APPLICATION = 'monitor.wsgi.application'
  80. # Database
  81. # https://docs.djangoproject.com/en/2.2/ref/settings/#databases
  82. DATABASES = {
  83. 'default': {
  84. 'ENGINE': 'django.db.backends.sqlite3',
  85. 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
  86. }
  87. }
  88. # Password validation
  89. # https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
  90. AUTH_PASSWORD_VALIDATORS = [
  91. {
  92. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  93. },
  94. {
  95. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  96. },
  97. {
  98. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  99. },
  100. {
  101. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  102. },
  103. ]
  104. # Internationalization
  105. # https://docs.djangoproject.com/en/2.2/topics/i18n/
  106. LANGUAGE_CODE = 'en-us'
  107. TIME_ZONE = 'UTC'
  108. USE_I18N = True
  109. USE_L10N = True
  110. USE_TZ = True
  111. # Static files (CSS, JavaScript, Images)
  112. # https://docs.djangoproject.com/en/2.2/howto/static-files/
  113. STATIC_URL = '/static/'