Skip to content

Commit 6259ab5

Browse files
authored
Update settings.py
1 parent 061a6b1 commit 6259ab5

File tree

1 file changed

+59
-48
lines changed

1 file changed

+59
-48
lines changed

settings.py

Lines changed: 59 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,57 @@
1+
"""
2+
Django settings for ons_trading project.
3+
4+
Generated by 'django-admin startproject' using Django 5.2.1.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.2/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.2/ref/settings/
11+
"""
12+
113
import os
214
from pathlib import Path
3-
import dj_database_url
15+
import dj_database_url # Import dj_database_url
416

5-
# -------------------------------------------------------------
6-
# BASE DIRECTORY
7-
# -------------------------------------------------------------
17+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
818
BASE_DIR = Path(__file__).resolve().parent.parent
919

10-
# -------------------------------------------------------------
11-
# SECURITY SETTINGS
12-
# -------------------------------------------------------------
13-
# Get the SECRET_KEY from Render's environment variable
14-
SECRET_KEY = os.environ.get('SECRET_KEY', 'django-insecure-default-key')
1520

16-
# Get DEBUG status from Render (defaults to False in production)
21+
# Quick-start development settings - unsuitable for production
22+
# See https://docs.djangoproject.com/en/5.2/howto/deployment/checklist/
23+
24+
# SECURITY WARNING: keep the secret key used in production secret!
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')
27+
28+
# SECURITY WARNING: don't run with debug turned on in production!
29+
# Get DEBUG status from a Render environment variable (defaults to False)
1730
DEBUG = os.environ.get('DEBUG', 'False') == 'True'
1831

19-
# ALLOWED_HOSTS: Add Render's external hostname automatically
32+
# Get the ALLOWED_HOSTS from Render's environment variable
2033
ALLOWED_HOSTS = []
2134
RENDER_EXTERNAL_HOSTNAME = os.environ.get('RENDER_EXTERNAL_HOSTNAME')
2235
if RENDER_EXTERNAL_HOSTNAME:
2336
ALLOWED_HOSTS.append(RENDER_EXTERNAL_HOSTNAME)
2437

25-
# -------------------------------------------------------------
26-
# INSTALLED APPS
27-
# -------------------------------------------------------------
38+
39+
# Application definition
40+
2841
INSTALLED_APPS = [
2942
"django.contrib.admin",
3043
"django.contrib.auth",
3144
"django.contrib.contenttypes",
3245
"django.contrib.sessions",
3346
"django.contrib.messages",
3447
"django.contrib.staticfiles",
35-
'onsapp', # Your custom app
48+
'onsapp',
3649
]
3750

38-
# -------------------------------------------------------------
39-
# MIDDLEWARE
40-
# -------------------------------------------------------------
4151
MIDDLEWARE = [
4252
"django.middleware.security.SecurityMiddleware",
43-
"whitenoise.middleware.WhiteNoiseMiddleware", # Required for Render
53+
# Add WhiteNoise middleware right after SecurityMiddleware
54+
'whitenoise.middleware.WhiteNoiseMiddleware',
4455
"django.contrib.sessions.middleware.SessionMiddleware",
4556
"django.middleware.common.CommonMiddleware",
4657
"django.middleware.csrf.CsrfViewMiddleware",
@@ -49,14 +60,8 @@
4960
"django.middleware.clickjacking.XFrameOptionsMiddleware",
5061
]
5162

52-
# -------------------------------------------------------------
53-
# URL CONFIGURATION
54-
# -------------------------------------------------------------
5563
ROOT_URLCONF = "ons_trading.urls"
5664

57-
# -------------------------------------------------------------
58-
# TEMPLATES
59-
# -------------------------------------------------------------
6065
TEMPLATES = [
6166
{
6267
"BACKEND": "django.template.backends.django.DjangoTemplates",
@@ -73,25 +78,25 @@
7378
},
7479
]
7580

76-
# -------------------------------------------------------------
77-
# WSGI APPLICATION
78-
# -------------------------------------------------------------
7981
WSGI_APPLICATION = "ons_trading.wsgi.application"
8082

81-
# -------------------------------------------------------------
82-
# DATABASE CONFIGURATION
83-
# -------------------------------------------------------------
84-
# Uses SQLite locally, but switches to PostgreSQL on Render automatically
83+
84+
# Database
85+
# https://docs.djangoproject.com/en/5.2/ref/settings/#databases
86+
87+
# This setup uses dj_database_url to read the DATABASE_URL env var from Render
8588
DATABASES = {
8689
'default': dj_database_url.config(
90+
# Use SQLite locally if DATABASE_URL is not set
8791
default=f'sqlite:///{BASE_DIR / "db.sqlite3"}',
8892
conn_max_age=600,
8993
)
9094
}
9195

92-
# -------------------------------------------------------------
93-
# PASSWORD VALIDATION
94-
# -------------------------------------------------------------
96+
97+
# Password validation
98+
# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
99+
95100
AUTH_PASSWORD_VALIDATORS = [
96101
{
97102
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
@@ -107,26 +112,32 @@
107112
},
108113
]
109114

110-
# -------------------------------------------------------------
111-
# INTERNATIONALIZATION
112-
# -------------------------------------------------------------
115+
116+
# Internationalization
117+
# https://docs.djangoproject.com/en/5.2/topics/i18n/
118+
113119
LANGUAGE_CODE = "en-us"
120+
114121
TIME_ZONE = 'Asia/Kolkata'
115-
USE_I18N = True
122+
123+
USE_I1N = True
124+
116125
USE_TZ = True
117126

118-
# -------------------------------------------------------------
119-
# STATIC FILES (CSS, JavaScript, Images)
120-
# -------------------------------------------------------------
121-
STATIC_URL = "/static/"
122127

123-
# This is crucial for Render deployment (fixes ImproperlyConfigured error)
128+
# Static files (CSS, JavaScript, Images)
129+
# https://docs.djangoproject.com/en/5.2/howto/static-files/
130+
131+
STATIC_URL = "static/"
132+
133+
# This is the directory where collectstatic will gather all static files.
124134
STATIC_ROOT = BASE_DIR / 'staticfiles'
125135

126-
# Enable WhiteNoise compression and caching
136+
# Enable WhiteNoise to serve static files efficiently.
127137
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
128138

129-
# -------------------------------------------------------------
130-
# DEFAULT AUTO FIELD
131-
# -------------------------------------------------------------
139+
140+
# Default primary key field type
141+
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
142+
132143
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

0 commit comments

Comments
 (0)