1
0

settings.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. DATABASES = {
  74. 'default': {
  75. 'ENGINE': 'django.db.backends.sqlite3',
  76. 'NAME': BASE_DIR / os.getenv('DATABASE_NAME', 'db.sqlite3'),
  77. }
  78. }
  79. # Password validation
  80. # https://docs.djangoproject.com/en/3.2/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.2/topics/i18n/
  97. LANGUAGE_CODE = 'fr-FR'
  98. TIME_ZONE = 'Europe/Paris'
  99. USE_I18N = True
  100. USE_L10N = True
  101. USE_TZ = True
  102. # Static files (CSS, JavaScript, Images)
  103. # https://docs.djangoproject.com/en/3.2/howto/static-files/
  104. STATIC_URL = '/static/'
  105. STATICFILES_DIRS = [
  106. BASE_DIR / "static",
  107. ]
  108. STATIC_ROOT = BASE_DIR / 'staticfiles'
  109. # Media files
  110. MEDIA_URL = '/media/'
  111. MEDIA_ROOT = BASE_DIR / 'media'
  112. # Default primary key field type
  113. # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
  114. DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
  115. # Security settings (décommenter en production)
  116. # SECURE_SSL_REDIRECT = True
  117. # SESSION_COOKIE_SECURE = True
  118. # CSRF_COOKIE_SECURE = True
  119. # SECURE_BROWSER_XSS_FILTER = True
  120. # SECURE_CONTENT_TYPE_NOSNIFF = True
  121. # X_FRAME_OPTIONS = 'DENY'
  122. # TinyMCE Configuration
  123. TINYMCE_DEFAULT_CONFIG = {
  124. 'height': 500,
  125. 'width': '100%',
  126. 'cleanup_on_startup': True,
  127. 'custom_undo_redo_levels': 20,
  128. 'selector': 'textarea',
  129. 'theme': 'silver',
  130. 'plugins': '''
  131. textcolor save link image media preview codesample contextmenu
  132. table code lists fullscreen insertdatetime nonbreaking
  133. contextmenu directionality searchreplace wordcount visualblocks
  134. visualchars code fullscreen autolink lists charmap print hr
  135. anchor pagebreak
  136. ''',
  137. 'toolbar1': '''
  138. fullscreen preview bold italic underline | fontselect,
  139. fontsizeselect | forecolor backcolor | alignleft alignright |
  140. aligncenter alignjustify | indent outdent | bullist numlist table |
  141. | link image media | codesample |
  142. ''',
  143. 'toolbar2': '''
  144. visualblocks visualchars |
  145. charmap hr pagebreak nonbreaking anchor | code |
  146. ''',
  147. 'contextmenu': 'formats | link image',
  148. 'menubar': True,
  149. 'statusbar': True,
  150. }