settings.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. """
  2. Django settings for duhaz_blog project.
  3. Generated by 'django-admin startproject' using Django 3.2.4.
  4. For more information on this file, see
  5. https://docs.djangoproject.com/en/3.2/topics/settings/
  6. For the full list of settings and their values, see
  7. https://docs.djangoproject.com/en/3.2/ref/settings/
  8. """
  9. from pathlib import Path
  10. import os
  11. from dotenv import load_dotenv
  12. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  13. BASE_DIR = Path(__file__).resolve().parent.parent
  14. # Charger les variables d'environnement depuis le fichier .env
  15. load_dotenv(BASE_DIR / '.env')
  16. # Quick-start development settings - unsuitable for production
  17. # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
  18. # SECURITY WARNING: keep the secret key used in production secret!
  19. SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-changez-moi-en-production')
  20. # SECURITY WARNING: don't run with debug turned on in production!
  21. DEBUG = os.getenv('DEBUG', 'False') == 'True'
  22. ALLOWED_HOSTS = os.getenv('ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',')
  23. # CSRF Protection - Domaines de confiance
  24. CSRF_TRUSTED_ORIGINS = [
  25. 'https://www.duhaz.fr',
  26. 'https://duhaz.fr',
  27. ]
  28. # Application definition
  29. INSTALLED_APPS = [
  30. 'django.contrib.admin',
  31. 'django.contrib.auth',
  32. 'django.contrib.contenttypes',
  33. 'django.contrib.sessions',
  34. 'django.contrib.messages',
  35. 'django.contrib.staticfiles',
  36. 'tinymce',
  37. 'import_export', # Réactivé pour test avec Python 3.13
  38. 'crispy_forms',
  39. 'crispy_bootstrap4',
  40. 'core',
  41. 'blog',
  42. ]
  43. CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4"
  44. CRISPY_TEMPLATE_PACK = 'bootstrap4'
  45. MIDDLEWARE = [
  46. 'django.middleware.security.SecurityMiddleware',
  47. 'django.contrib.sessions.middleware.SessionMiddleware',
  48. 'django.middleware.common.CommonMiddleware',
  49. 'django.middleware.csrf.CsrfViewMiddleware',
  50. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  51. 'django.contrib.messages.middleware.MessageMiddleware',
  52. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  53. ]
  54. ROOT_URLCONF = 'duhaz_blog.urls'
  55. TEMPLATES = [
  56. {
  57. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  58. 'DIRS': [],
  59. 'APP_DIRS': True,
  60. 'OPTIONS': {
  61. 'context_processors': [
  62. 'django.template.context_processors.debug',
  63. 'django.template.context_processors.request',
  64. 'django.contrib.auth.context_processors.auth',
  65. 'django.contrib.messages.context_processors.messages',
  66. ],
  67. },
  68. },
  69. ]
  70. WSGI_APPLICATION = 'duhaz_blog.wsgi.application'
  71. # Database
  72. # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
  73. # Configuration dynamique selon le moteur de base de données
  74. DB_ENGINE = os.getenv('DB_ENGINE', 'sqlite3')
  75. if DB_ENGINE == 'mysql':
  76. # Configuration MariaDB/MySQL
  77. DATABASES = {
  78. 'default': {
  79. 'ENGINE': 'django.db.backends.mysql',
  80. 'NAME': os.getenv('DB_NAME', 'duhaz_blog'),
  81. 'USER': os.getenv('DB_USER', 'root'),
  82. 'PASSWORD': os.getenv('DB_PASSWORD', ''),
  83. 'HOST': os.getenv('DB_HOST', 'localhost'),
  84. 'PORT': os.getenv('DB_PORT', '3306'),
  85. 'OPTIONS': {
  86. 'charset': 'utf8mb4',
  87. 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
  88. },
  89. }
  90. }
  91. else:
  92. # Configuration SQLite (par défaut)
  93. DATABASES = {
  94. 'default': {
  95. 'ENGINE': 'django.db.backends.sqlite3',
  96. 'NAME': BASE_DIR / os.getenv('DATABASE_NAME', 'db.sqlite3'),
  97. }
  98. }
  99. # Password validation
  100. # https://docs.djangoproject.com/en/3.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/3.2/topics/i18n/
  117. LANGUAGE_CODE = 'fr-FR'
  118. TIME_ZONE = 'Europe/Paris'
  119. USE_I18N = True
  120. USE_L10N = True
  121. USE_TZ = True
  122. # Static files (CSS, JavaScript, Images)
  123. # https://docs.djangoproject.com/en/3.2/howto/static-files/
  124. STATIC_URL = '/static/'
  125. STATICFILES_DIRS = [
  126. BASE_DIR / "static",
  127. ]
  128. STATIC_ROOT = BASE_DIR / 'staticfiles'
  129. # Media files
  130. MEDIA_URL = '/media/'
  131. MEDIA_ROOT = BASE_DIR / 'media'
  132. # Default primary key field type
  133. # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
  134. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  135. # Security settings (décommenter en production)
  136. # SECURE_SSL_REDIRECT = True
  137. # SESSION_COOKIE_SECURE = True
  138. # CSRF_COOKIE_SECURE = True
  139. # SECURE_BROWSER_XSS_FILTER = True
  140. # SECURE_CONTENT_TYPE_NOSNIFF = True
  141. # X_FRAME_OPTIONS = 'DENY'
  142. # TinyMCE Configuration
  143. TINYMCE_DEFAULT_CONFIG = {
  144. 'height': 500,
  145. 'width': '100%',
  146. 'cleanup_on_startup': True,
  147. 'custom_undo_redo_levels': 20,
  148. 'selector': 'textarea',
  149. 'theme': 'silver',
  150. 'plugins': '''
  151. textcolor save link image media preview codesample contextmenu
  152. table code lists fullscreen insertdatetime nonbreaking
  153. contextmenu directionality searchreplace wordcount visualblocks
  154. visualchars code fullscreen autolink lists charmap print hr
  155. anchor pagebreak
  156. ''',
  157. 'toolbar1': '''
  158. fullscreen preview bold italic underline | fontselect,
  159. fontsizeselect | forecolor backcolor | alignleft alignright |
  160. aligncenter alignjustify | indent outdent | bullist numlist table |
  161. | link image media | codesample |
  162. ''',
  163. 'toolbar2': '''
  164. visualblocks visualchars |
  165. charmap hr pagebreak nonbreaking anchor | code |
  166. ''',
  167. 'contextmenu': 'formats | link image',
  168. 'menubar': True,
  169. 'statusbar': True,
  170. }