1212
1313import os
1414from pathlib import Path
15+ import dj_database_url # Import dj_database_url
1516
1617# Build paths inside the project like this: BASE_DIR / 'subdir'.
1718BASE_DIR = Path (__file__ ).resolve ().parent .parent
2122# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
2223
2324# SECURITY WARNING: keep the secret key used in production secret!
24- SECRET_KEY = "django-insecure-n&a6vut67vp5ysh09jvsts&6%m5e*b_#hr82iuw(1dk^d18yok"
25+ # Get the SECRET_KEY from a Render environment variable
26+ SECRET_KEY = os .environ .get ('SECRET_KEY' , 'django-insecure-n&a6vut67vp5ysh09jvsts&6%m5e*b_#hr82iuw(1dk^d18yok' )
2527
2628# SECURITY WARNING: don't run with debug turned on in production!
27- DEBUG = True
29+ # Get DEBUG status from a Render environment variable (defaults to False)
30+ DEBUG = os .environ .get ('DEBUG' , 'False' ) == 'True'
2831
32+ # Get the ALLOWED_HOSTS from Render's environment variable
2933ALLOWED_HOSTS = []
34+ RENDER_EXTERNAL_HOSTNAME = os .environ .get ('RENDER_EXTERNAL_HOSTNAME' )
35+ if RENDER_EXTERNAL_HOSTNAME :
36+ ALLOWED_HOSTS .append (RENDER_EXTERNAL_HOSTNAME )
3037
3138
3239# Application definition
4350
4451MIDDLEWARE = [
4552 "django.middleware.security.SecurityMiddleware" ,
53+ # Add WhiteNoise middleware right after SecurityMiddleware
54+ 'whitenoise.middleware.WhiteNoiseMiddleware' ,
4655 "django.contrib.sessions.middleware.SessionMiddleware" ,
4756 "django.middleware.common.CommonMiddleware" ,
4857 "django.middleware.csrf.CsrfViewMiddleware" ,
7584# Database
7685# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
7786
87+ # This setup uses dj_database_url to read the DATABASE_URL env var from Render
7888DATABASES = {
79- 'default' : {
80- 'ENGINE' : 'django.db.backends.sqlite3' ,
81- 'NAME' : BASE_DIR / "db.sqlite3" ,
82- }
89+ 'default' : dj_database_url .config (
90+ # Use SQLite locally if DATABASE_URL is not set
91+ default = f'sqlite:///{ BASE_DIR / "db.sqlite3" } ' ,
92+ conn_max_age = 600 ,
93+ )
8394}
8495
8596
8697# Password validation
8798# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
8899
89- AUTH_PASSWORD_VALIDATORS = [
100+ AUTH_PASSWORD_validators = [
90101 {
91102 "NAME" : "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" ,
92103 },
109120
110121TIME_ZONE = 'Asia/Kolkata'
111122
112- USE_I18N = True
123+ USE_I1N = True
113124
114125USE_TZ = True
115126
119130
120131STATIC_URL = "static/"
121132
133+ # This is the directory where collectstatic will gather all static files.
134+ STATIC_ROOT = BASE_DIR / 'staticfiles'
135+
136+ # Enable WhiteNoise to serve static files efficiently.
137+ STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
138+
139+
122140# Default primary key field type
123141# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
124142
125- DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
143+ DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
0 commit comments