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