|
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 | | - |
13 | 1 | import os |
14 | 2 | from pathlib import Path |
15 | | -import dj_database_url # Import dj_database_url |
| 3 | +import dj_database_url |
16 | 4 |
|
17 | | -# Build paths inside the project like this: BASE_DIR / 'subdir'. |
| 5 | +# ------------------------------------------------------------- |
| 6 | +# BASE DIRECTORY |
| 7 | +# ------------------------------------------------------------- |
18 | 8 | BASE_DIR = Path(__file__).resolve().parent.parent |
19 | 9 |
|
| 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') |
20 | 15 |
|
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) |
| 16 | +# Get DEBUG status from Render (defaults to False in production) |
30 | 17 | DEBUG = os.environ.get('DEBUG', 'False') == 'True' |
31 | 18 |
|
32 | | -# Get the ALLOWED_HOSTS from Render's environment variable |
| 19 | +# ALLOWED_HOSTS: Add Render's external hostname automatically |
33 | 20 | ALLOWED_HOSTS = [] |
34 | 21 | RENDER_EXTERNAL_HOSTNAME = os.environ.get('RENDER_EXTERNAL_HOSTNAME') |
35 | 22 | if RENDER_EXTERNAL_HOSTNAME: |
36 | 23 | ALLOWED_HOSTS.append(RENDER_EXTERNAL_HOSTNAME) |
37 | 24 |
|
38 | | - |
39 | | -# Application definition |
40 | | - |
| 25 | +# ------------------------------------------------------------- |
| 26 | +# INSTALLED APPS |
| 27 | +# ------------------------------------------------------------- |
41 | 28 | INSTALLED_APPS = [ |
42 | 29 | "django.contrib.admin", |
43 | 30 | "django.contrib.auth", |
44 | 31 | "django.contrib.contenttypes", |
45 | 32 | "django.contrib.sessions", |
46 | 33 | "django.contrib.messages", |
47 | 34 | "django.contrib.staticfiles", |
48 | | - 'onsapp', |
| 35 | + 'onsapp', # Your custom app |
49 | 36 | ] |
50 | 37 |
|
| 38 | +# ------------------------------------------------------------- |
| 39 | +# MIDDLEWARE |
| 40 | +# ------------------------------------------------------------- |
51 | 41 | MIDDLEWARE = [ |
52 | 42 | "django.middleware.security.SecurityMiddleware", |
53 | | - # Add WhiteNoise middleware right after SecurityMiddleware |
54 | | - 'whitenoise.middleware.WhiteNoiseMiddleware', |
| 43 | + "whitenoise.middleware.WhiteNoiseMiddleware", # Required for Render |
55 | 44 | "django.contrib.sessions.middleware.SessionMiddleware", |
56 | 45 | "django.middleware.common.CommonMiddleware", |
57 | 46 | "django.middleware.csrf.CsrfViewMiddleware", |
|
60 | 49 | "django.middleware.clickjacking.XFrameOptionsMiddleware", |
61 | 50 | ] |
62 | 51 |
|
| 52 | +# ------------------------------------------------------------- |
| 53 | +# URL CONFIGURATION |
| 54 | +# ------------------------------------------------------------- |
63 | 55 | ROOT_URLCONF = "ons_trading.urls" |
64 | 56 |
|
| 57 | +# ------------------------------------------------------------- |
| 58 | +# TEMPLATES |
| 59 | +# ------------------------------------------------------------- |
65 | 60 | TEMPLATES = [ |
66 | 61 | { |
67 | 62 | "BACKEND": "django.template.backends.django.DjangoTemplates", |
|
78 | 73 | }, |
79 | 74 | ] |
80 | 75 |
|
| 76 | +# ------------------------------------------------------------- |
| 77 | +# WSGI APPLICATION |
| 78 | +# ------------------------------------------------------------- |
81 | 79 | WSGI_APPLICATION = "ons_trading.wsgi.application" |
82 | 80 |
|
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 |
| 81 | +# ------------------------------------------------------------- |
| 82 | +# DATABASE CONFIGURATION |
| 83 | +# ------------------------------------------------------------- |
| 84 | +# Uses SQLite locally, but switches to PostgreSQL on Render automatically |
88 | 85 | DATABASES = { |
89 | 86 | 'default': dj_database_url.config( |
90 | | - # Use SQLite locally if DATABASE_URL is not set |
91 | 87 | default=f'sqlite:///{BASE_DIR / "db.sqlite3"}', |
92 | 88 | conn_max_age=600, |
93 | 89 | ) |
94 | 90 | } |
95 | 91 |
|
96 | | - |
97 | | -# Password validation |
98 | | -# https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators |
99 | | - |
| 92 | +# ------------------------------------------------------------- |
| 93 | +# PASSWORD VALIDATION |
| 94 | +# ------------------------------------------------------------- |
100 | 95 | AUTH_PASSWORD_VALIDATORS = [ |
101 | 96 | { |
102 | 97 | "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator", |
|
112 | 107 | }, |
113 | 108 | ] |
114 | 109 |
|
115 | | - |
116 | | -# Internationalization |
117 | | -# https://docs.djangoproject.com/en/5.2/topics/i18n/ |
118 | | - |
| 110 | +# ------------------------------------------------------------- |
| 111 | +# INTERNATIONALIZATION |
| 112 | +# ------------------------------------------------------------- |
119 | 113 | LANGUAGE_CODE = "en-us" |
120 | | - |
121 | 114 | TIME_ZONE = 'Asia/Kolkata' |
122 | | - |
123 | | -USE_I1N = True |
124 | | - |
| 115 | +USE_I18N = True |
125 | 116 | USE_TZ = True |
126 | 117 |
|
| 118 | +# ------------------------------------------------------------- |
| 119 | +# STATIC FILES (CSS, JavaScript, Images) |
| 120 | +# ------------------------------------------------------------- |
| 121 | +STATIC_URL = "/static/" |
127 | 122 |
|
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. |
| 123 | +# This is crucial for Render deployment (fixes ImproperlyConfigured error) |
134 | 124 | STATIC_ROOT = BASE_DIR / 'staticfiles' |
135 | 125 |
|
136 | | -# Enable WhiteNoise to serve static files efficiently. |
| 126 | +# Enable WhiteNoise compression and caching |
137 | 127 | STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' |
138 | 128 |
|
139 | | - |
140 | | -# Default primary key field type |
141 | | -# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field |
142 | | - |
| 129 | +# ------------------------------------------------------------- |
| 130 | +# DEFAULT AUTO FIELD |
| 131 | +# ------------------------------------------------------------- |
143 | 132 | DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" |
0 commit comments