1
0

settings.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. 'django.contrib.sites', # Requis pour le sitemap
  37. 'django.contrib.sitemaps', # Pour le sitemap dynamique
  38. 'tinymce',
  39. 'import_export', # Réactivé pour test avec Python 3.13
  40. 'crispy_forms',
  41. 'crispy_bootstrap4',
  42. 'core',
  43. 'blog',
  44. ]
  45. CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4"
  46. CRISPY_TEMPLATE_PACK = 'bootstrap4'
  47. MIDDLEWARE = [
  48. 'django.middleware.security.SecurityMiddleware',
  49. 'django.contrib.sessions.middleware.SessionMiddleware',
  50. 'django.middleware.common.CommonMiddleware',
  51. 'django.middleware.csrf.CsrfViewMiddleware',
  52. 'django.contrib.auth.middleware.AuthenticationMiddleware',
  53. 'django.contrib.messages.middleware.MessageMiddleware',
  54. 'django.middleware.clickjacking.XFrameOptionsMiddleware',
  55. ]
  56. ROOT_URLCONF = 'duhaz_blog.urls'
  57. TEMPLATES = [
  58. {
  59. 'BACKEND': 'django.template.backends.django.DjangoTemplates',
  60. 'DIRS': [],
  61. 'APP_DIRS': True,
  62. 'OPTIONS': {
  63. 'context_processors': [
  64. 'django.template.context_processors.debug',
  65. 'django.template.context_processors.request',
  66. 'django.contrib.auth.context_processors.auth',
  67. 'django.contrib.messages.context_processors.messages',
  68. ],
  69. },
  70. },
  71. ]
  72. WSGI_APPLICATION = 'duhaz_blog.wsgi.application'
  73. # Database
  74. # https://docs.djangoproject.com/en/3.2/ref/settings/#databases
  75. # Configuration dynamique selon le moteur de base de données
  76. DB_ENGINE = os.getenv('DB_ENGINE', 'sqlite3')
  77. if DB_ENGINE == 'mysql':
  78. # Configuration MariaDB/MySQL
  79. DATABASES = {
  80. 'default': {
  81. 'ENGINE': 'django.db.backends.mysql',
  82. 'NAME': os.getenv('DB_NAME', 'duhaz_blog'),
  83. 'USER': os.getenv('DB_USER', 'root'),
  84. 'PASSWORD': os.getenv('DB_PASSWORD', ''),
  85. 'HOST': os.getenv('DB_HOST', 'localhost'),
  86. 'PORT': os.getenv('DB_PORT', '3306'),
  87. 'OPTIONS': {
  88. 'charset': 'utf8mb4',
  89. 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'",
  90. },
  91. }
  92. }
  93. else:
  94. # Configuration SQLite (par défaut)
  95. DATABASES = {
  96. 'default': {
  97. 'ENGINE': 'django.db.backends.sqlite3',
  98. 'NAME': BASE_DIR / os.getenv('DATABASE_NAME', 'db.sqlite3'),
  99. }
  100. }
  101. # Password validation
  102. # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
  103. AUTH_PASSWORD_VALIDATORS = [
  104. {
  105. 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
  106. },
  107. {
  108. 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
  109. },
  110. {
  111. 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
  112. },
  113. {
  114. 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
  115. },
  116. ]
  117. # Internationalization
  118. # https://docs.djangoproject.com/en/3.2/topics/i18n/
  119. LANGUAGE_CODE = 'fr-FR'
  120. TIME_ZONE = 'Europe/Paris'
  121. USE_I18N = True
  122. USE_L10N = True
  123. USE_TZ = True
  124. # Static files (CSS, JavaScript, Images)
  125. # https://docs.djangoproject.com/en/3.2/howto/static-files/
  126. STATIC_URL = '/static/'
  127. STATICFILES_DIRS = [
  128. BASE_DIR / "static",
  129. ]
  130. STATIC_ROOT = BASE_DIR / 'staticfiles'
  131. # Media files
  132. MEDIA_URL = '/media/'
  133. MEDIA_ROOT = BASE_DIR / 'media'
  134. # Default primary key field type
  135. # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
  136. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  137. # Security settings (décommenter en production)
  138. # SECURE_SSL_REDIRECT = True
  139. # SESSION_COOKIE_SECURE = True
  140. # CSRF_COOKIE_SECURE = True
  141. # SECURE_BROWSER_XSS_FILTER = True
  142. # SECURE_CONTENT_TYPE_NOSNIFF = True
  143. # X_FRAME_OPTIONS = 'DENY'
  144. # TinyMCE Configuration
  145. TINYMCE_DEFAULT_CONFIG = {
  146. 'height': 500,
  147. 'width': '100%',
  148. 'cleanup_on_startup': True,
  149. 'custom_undo_redo_levels': 20,
  150. 'selector': 'textarea',
  151. 'theme': 'silver',
  152. 'plugins': '''
  153. textcolor save link image media preview codesample contextmenu
  154. table code lists fullscreen insertdatetime nonbreaking
  155. contextmenu directionality searchreplace wordcount visualblocks
  156. visualchars code fullscreen autolink lists charmap print hr
  157. anchor pagebreak
  158. ''',
  159. 'toolbar1': '''
  160. fullscreen preview bold italic underline | fontselect,
  161. fontsizeselect | forecolor backcolor | alignleft alignright |
  162. aligncenter alignjustify | indent outdent | bullist numlist table |
  163. | link image media | codesample |
  164. ''',
  165. 'toolbar2': '''
  166. visualblocks visualchars |
  167. charmap hr pagebreak nonbreaking anchor | code |
  168. ''',
  169. 'contextmenu': 'formats | link image',
  170. 'menubar': True,
  171. 'statusbar': True,
  172. }
  173. # Configuration pour django.contrib.sites (requis pour sitemaps)
  174. SITE_ID = 1