settings.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. """
  2. Django settings for server project.
  3. Generated by 'django-admin startproject' using Django 3.1.7.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/3.1/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/3.1/ref/settings/
  8. """
  9. from pathlib import Path
  10. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  11. BASE_DIR = Path(__file__).resolve().parent.parent
  12. # Quick-start development settings - unsuitable for production
  13. # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
  14. # SECURITY WARNING: keep the secret key used in production secret!
  15. SECRET_KEY = 'b06y0-4h3ao9mdkdfn0r^1@!9r6)&8-q*!f8q_^1hvrw=ri95_'
  16. # SECURITY WARNING: don't run with debug turned on in production!
  17. DEBUG = True
  18. ALLOWED_HOSTS = []
  19. # Application definition
  20. INSTALLED_APPS = [
  21. 'django.contrib.admin',
  22. 'django.contrib.auth',
  23. 'django.contrib.contenttypes',
  24. 'django.contrib.sessions',
  25. 'django.contrib.messages',
  26. 'django.contrib.staticfiles',
  27. 'api',
  28. 'corsheaders',
  29. 'rest_framework'
  30. ]
  31. MIDDLEWARE = [
  32. 'django.middleware.security.SecurityMiddleware',
  33. 'django.contrib.sessions.middleware.SessionMiddleware',
  34. 'corsheaders.middleware.CorsMiddleware', # 添加跨域中间件,需注意顺序
  35. 'django.middleware.common.CommonMiddleware',
  36. # 'django.middleware.csrf.CsrfViewMiddleware',
  37. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  38. 'django.contrib.messages.middleware.MessageMiddleware',
  39. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  40. ]
  41. CORS_ALLOW_CREDENTIALS = True
  42. CORS_ORIGIN_ALLOW_ALL = True
  43. # 指定白名单
  44. # CORS_ORIGIN_WHITELIST = (
  45. # 'http://google.com',
  46. # 'http://hostname.example.com',
  47. # 'http://localhost:8000',
  48. # 'http://127.0.0.1:9000'
  49. # )
  50. ROOT_URLCONF = 'server.urls'
  51. TEMPLATES = [
  52. {
  53. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  54. 'DIRS': [],
  55. 'APP_DIRS': True,
  56. 'OPTIONS': {
  57. 'context_processors': [
  58. 'django.template.context_processors.debug',
  59. 'django.template.context_processors.request',
  60. 'django.contrib.auth.context_processors.auth',
  61. 'django.contrib.messages.context_processors.messages',
  62. ],
  63. },
  64. },
  65. ]
  66. WSGI_APPLICATION = 'server.wsgi.application'
  67. # Database
  68. # https://docs.djangoproject.com/en/3.1/ref/settings/#databases
  69. DATABASES = {
  70. 'default': {
  71. 'ENGINE': 'django.db.backends.mysql',
  72. 'NAME': 'ant_backend', # 数据库名
  73. 'HOST': '127.0.0.1',
  74. 'USER': 'root',
  75. 'PASSWORD': 'password',
  76. 'PORT': 3306
  77. }
  78. }
  79. # Password validation
  80. # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
  81. AUTH_PASSWORD_VALIDATORS = [
  82. {
  83. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  84. },
  85. {
  86. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  87. },
  88. {
  89. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  90. },
  91. {
  92. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  93. },
  94. ]
  95. # Internationalization
  96. # https://docs.djangoproject.com/en/3.1/topics/i18n/
  97. LANGUAGE_CODE = 'zh-hans'
  98. TIME_ZONE = 'Asia/Shanghai'
  99. USE_I18N = True
  100. USE_L10N = True
  101. USE_TZ = False
  102. # Static files (CSS, JavaScript, Images)
  103. # https://docs.djangoproject.com/en/3.1/howto/static-files/
  104. STATIC_URL = '/static/'