settings.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. """
  2. Django settings for app project.
  3. Generated by 'django-admin startproject' using Django 4.0.6.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/4.0/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/4.0/ref/settings/
  8. """
  9. import os
  10. import json
  11. import socket
  12. from pathlib import Path
  13. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  14. BASE_DIR = Path(__file__).resolve().parent.parent
  15. # Quick-start development settings - unsuitable for production
  16. # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
  17. # SECURITY WARNING: keep the secret key used in production secret!
  18. SECRET_KEY = os.getenv('DJANGO_SECRET_KEY', 'debug_secret_key')
  19. # SECURITY WARNING: don't run with debug turned on in production!
  20. DEBUG = os.getenv('DJANGO_DEBUG', "True") == "True"
  21. if DEBUG:
  22. hostname, _, ips = socket.gethostbyname_ex(socket.gethostname())
  23. INTERNAL_IPS = [ip[: ip.rfind(".")] + ".1" for ip in ips] + ["127.0.0.1", "localhost"]
  24. ALLOWED_HOSTS = os.getenv('DJANGO_ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',')
  25. CSRF_TRUSTED_ORIGINS = os.getenv('DJANGO_CSRF_TRUSTED_ORIGINS', 'http://localhost').split(',')
  26. # Application definition
  27. INSTALLED_APPS = [
  28. 'zitap.apps.ZitapConfig',
  29. 'django.contrib.admin',
  30. 'django.contrib.auth',
  31. 'django.contrib.contenttypes',
  32. 'django.contrib.sessions',
  33. 'django.contrib.messages',
  34. 'django.contrib.staticfiles',
  35. ]
  36. MIDDLEWARE = [
  37. 'django.middleware.security.SecurityMiddleware',
  38. 'django.contrib.sessions.middleware.SessionMiddleware',
  39. 'django.middleware.common.CommonMiddleware',
  40. 'django.middleware.csrf.CsrfViewMiddleware',
  41. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  42. 'django.contrib.messages.middleware.MessageMiddleware',
  43. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  44. ]
  45. LOCALE_PATHS = ( os.path.join(BASE_DIR, 'locale'), )
  46. ROOT_URLCONF = 'project.urls'
  47. TEMPLATES = [
  48. {
  49. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  50. 'DIRS': [],
  51. 'APP_DIRS': True,
  52. 'OPTIONS': {
  53. 'context_processors': [
  54. 'django.template.context_processors.debug',
  55. 'django.template.context_processors.request',
  56. 'django.contrib.auth.context_processors.auth',
  57. 'django.contrib.messages.context_processors.messages',
  58. ],
  59. },
  60. },
  61. ]
  62. WSGI_APPLICATION = 'project.wsgi.application'
  63. # Database
  64. # https://docs.djangoproject.com/en/4.0/ref/settings/#databases
  65. DATABASES = {
  66. 'default': {
  67. 'ENGINE': 'django.db.backends.sqlite3',
  68. 'NAME': BASE_DIR / 'db.sqlite3',
  69. }
  70. }
  71. DATABASES = {
  72. 'default': {
  73. 'ENGINE': os.getenv('DATABASE_ENGINE', 'django.db.backends.sqlite3'),
  74. 'NAME': os.getenv('DATABASE_NAME', 'db.sqlite3'),
  75. 'USER': os.getenv('DATABASE_USERNAME', 'myprojectuser'),
  76. 'PASSWORD': os.getenv('DATABASE_PASSWORD', 'password'),
  77. 'HOST': os.getenv('DATABASE_HOST', '127.0.0.1'),
  78. 'PORT': os.getenv('DATABASE_PORT', 3306),
  79. 'OPTIONS': json.loads(
  80. os.getenv('DATABASE_OPTIONS', '{}')
  81. ),
  82. }
  83. }
  84. # Password validation
  85. # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
  86. AUTH_PASSWORD_VALIDATORS = [
  87. {
  88. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  89. },
  90. {
  91. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  92. },
  93. {
  94. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  95. },
  96. {
  97. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  98. },
  99. ]
  100. # Internationalization
  101. # https://docs.djangoproject.com/en/4.0/topics/i18n/
  102. LANGUAGE_CODE = 'en-us'
  103. TIME_ZONE = 'UTC'
  104. USE_I18N = True
  105. USE_L10N = True
  106. USE_TZ = True
  107. # Static files (CSS, JavaScript, Images)
  108. # https://docs.djangoproject.com/en/4.0/howto/static-files/
  109. STATIC_URL = 'static/'
  110. STATIC_ROOT = '../static'
  111. # Default primary key field type
  112. # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
  113. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  114. MEDIA_ROOT = os.path.join(BASE_DIR, '../data')