|
1 | 1 | import os |
2 | 2 | from pathlib import Path |
3 | | -import dj_database_url |
| 3 | +import dj_database_url # Make sure this is imported |
4 | 4 |
|
5 | | -# ------------------------------------------------------------- |
6 | | -# BASE DIRECTORY |
7 | | -# ------------------------------------------------------------- |
| 5 | +# Build paths inside the project like this: BASE_DIR / 'subdir'. |
8 | 6 | BASE_DIR = Path(__file__).resolve().parent.parent |
9 | 7 |
|
10 | | -# ------------------------------------------------------------- |
11 | | -# SECURITY SETTINGS |
12 | | -# ------------------------------------------------------------- |
13 | | -SECRET_KEY = os.environ.get('SECRET_KEY', 'dev-secret-key') |
14 | | -DEBUG = os.environ.get('DEBUG', 'True') == 'True' |
15 | | -ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '*').split(',') |
| 8 | +# SECURITY WARNING: keep the secret key used in production secret! |
| 9 | +# Get the SECRET_KEY from a Render environment variable |
| 10 | +SECRET_KEY = os.environ.get('SECRET_KEY', 'default-dev-secret-key-replace-me') |
16 | 11 |
|
17 | | -# ------------------------------------------------------------- |
18 | | -# INSTALLED APPS |
19 | | -# ------------------------------------------------------------- |
| 12 | +# SECURITY WARNING: don't run with debug turned on in production! |
| 13 | +# Get DEBUG status from a Render environment variable |
| 14 | +DEBUG = os.environ.get('DEBUG', 'False') == 'True' |
| 15 | + |
| 16 | +# Get the ALLOWED_HOSTS from Render's environment variable |
| 17 | +ALLOWED_HOSTS = [] |
| 18 | +RENDER_EXTERNAL_HOSTNAME = os.environ.get('RENDER_EXTERNAL_HOSTNAME') |
| 19 | +if RENDER_EXTERNAL_HOSTNAME: |
| 20 | + ALLOWED_HOSTS.append(RENDER_EXTERNAL_HOSTNAME) |
| 21 | + |
| 22 | +# Application definition |
20 | 23 | INSTALLED_APPS = [ |
21 | | - 'django.contrib.admin', |
22 | | - 'django.contrib.auth', |
23 | | - 'django.contrib.contenttypes', |
24 | | - 'django.contrib.sessions', |
25 | | - 'django.contrib.messages', |
26 | | - 'django.contrib.staticfiles', |
27 | | - # Add your custom apps below |
| 24 | + "django.contrib.admin", |
| 25 | + "django.contrib.auth", |
| 26 | + "django.contrib.contenttypes", |
| 27 | + "django.contrib.sessions", |
| 28 | + "django.contrib.messages", |
| 29 | + "django.contrib.staticfiles", |
| 30 | + 'onsapp', # Your app |
28 | 31 | ] |
29 | 32 |
|
30 | | -# ------------------------------------------------------------- |
31 | | -# MIDDLEWARE |
32 | | -# ------------------------------------------------------------- |
33 | 33 | MIDDLEWARE = [ |
34 | | - 'django.middleware.security.SecurityMiddleware', |
35 | | - |
36 | | - # WhiteNoise for static files on Render |
| 34 | + "django.middleware.security.SecurityMiddleware", |
| 35 | + # Add WhiteNoise middleware right after SecurityMiddleware |
37 | 36 | 'whitenoise.middleware.WhiteNoiseMiddleware', |
38 | | - |
39 | | - 'django.contrib.sessions.middleware.SessionMiddleware', |
40 | | - 'django.middleware.common.CommonMiddleware', |
41 | | - 'django.middleware.csrf.CsrfViewMiddleware', |
42 | | - 'django.contrib.auth.middleware.AuthenticationMiddleware', |
43 | | - 'django.contrib.messages.middleware.MessageMiddleware', |
44 | | - 'django.middleware.clickjacking.XFrameOptionsMiddleware', |
| 37 | + "django.contrib.sessions.middleware.SessionMiddleware", |
| 38 | + "django.middleware.common.CommonMiddleware", |
| 39 | + "django.middleware.csrf.CsrfViewMiddleware", |
| 40 | + "django.contrib.auth.middleware.AuthenticationMiddleware", |
| 41 | + "django.contrib.messages.middleware.MessageMiddleware", |
| 42 | + "django.middleware.clickjacking.XFrameOptionsMiddleware", |
45 | 43 | ] |
46 | 44 |
|
47 | | -# ------------------------------------------------------------- |
48 | | -# URL CONFIGURATION |
49 | | -# ------------------------------------------------------------- |
50 | | -ROOT_URLCONF = 'your_project_name.urls' |
| 45 | +ROOT_URLCONF = "ons_trading.urls" # Corrected from your_project_name |
51 | 46 |
|
52 | | -# ------------------------------------------------------------- |
53 | | -# TEMPLATES |
54 | | -# ------------------------------------------------------------- |
55 | 47 | TEMPLATES = [ |
56 | 48 | { |
57 | | - 'BACKEND': 'django.template.backends.django.DjangoTemplates', |
58 | | - 'DIRS': [BASE_DIR / 'templates'], # Your HTML templates directory |
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', |
| 49 | + "BACKEND": "django.template.backends.django.DjangoTemplates", |
| 50 | + "DIRS": [], |
| 51 | + "APP_DIRS": True, |
| 52 | + "OPTIONS": { |
| 53 | + "context_processors": [ |
| 54 | + "django.template.context_processors.debug", |
| 55 | + "django.template.context_processors.request", |
| 56 | + "django.contrib.auth.context_processors.auth", |
| 57 | + "django.contrib.messages.context_processors.messages", |
66 | 58 | ], |
67 | 59 | }, |
68 | 60 | }, |
69 | 61 | ] |
70 | 62 |
|
71 | | -# ------------------------------------------------------------- |
72 | | -# WSGI APPLICATION |
73 | | -# ------------------------------------------------------------- |
74 | | -WSGI_APPLICATION = 'your_project_name.wsgi.application' |
| 63 | +WSGI_APPLICATION = "ons_trading.wsgi.application" # Corrected from your_project_name |
75 | 64 |
|
76 | | -# ------------------------------------------------------------- |
77 | | -# DATABASE CONFIGURATION |
78 | | -# ------------------------------------------------------------- |
79 | | -# Uses SQLite by default, automatically switches to PostgreSQL if DATABASE_URL is set |
| 65 | +# Database |
| 66 | +# https://docs.djangoproject.com/en/5.2/ref/settings/#databases |
| 67 | +# This setup uses dj_database_url to read the DATABASE_URL env var from Render |
80 | 68 | DATABASES = { |
81 | 69 | 'default': dj_database_url.config( |
| 70 | + # Use SQLite locally if DATABASE_URL is not set |
82 | 71 | default=f'sqlite:///{BASE_DIR / "db.sqlite3"}', |
83 | 72 | conn_max_age=600, |
84 | 73 | ) |
85 | 74 | } |
86 | 75 |
|
87 | | -# ------------------------------------------------------------- |
88 | | -# PASSWORD VALIDATION |
89 | | -# ------------------------------------------------------------- |
| 76 | +# Password validation |
90 | 77 | AUTH_PASSWORD_VALIDATORS = [ |
91 | | - {'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',}, |
92 | | - {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',}, |
93 | | - {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',}, |
94 | | - {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',}, |
| 78 | + {"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",}, |
| 79 | + {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",}, |
| 80 | + {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",}, |
| 81 | + {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",}, |
95 | 82 | ] |
96 | 83 |
|
97 | | -# ------------------------------------------------------------- |
98 | | -# INTERNATIONALIZATION |
99 | | -# ------------------------------------------------------------- |
100 | | -LANGUAGE_CODE = 'en-us' |
101 | | -TIME_ZONE = 'Asia/Kolkata' # your local timezone |
| 84 | +# Internationalization |
| 85 | +LANGUAGE_CODE = "en-us" |
| 86 | +TIME_ZONE = 'Asia/Kolkata' |
102 | 87 | USE_I18N = True |
103 | 88 | USE_TZ = True |
104 | 89 |
|
105 | | -# ------------------------------------------------------------- |
106 | | -# STATIC FILES (CSS, JS, IMAGES) |
107 | | -# ------------------------------------------------------------- |
108 | | -STATIC_URL = '/static/' |
| 90 | +# Static files (CSS, JavaScript, Images) |
| 91 | +# https://docs.djangoproject.com/en/5.2/howto/static-files/ |
| 92 | +STATIC_URL = "/static/" |
| 93 | +# This is where collectstatic will gather files for WhiteNoise |
109 | 94 | STATIC_ROOT = BASE_DIR / 'staticfiles' |
110 | 95 |
|
111 | | -# Extra directories (optional) |
112 | | -STATICFILES_DIRS = [ |
113 | | - BASE_DIR / 'static', # if you have a 'static' folder |
114 | | -] |
115 | | - |
116 | | -# Enable WhiteNoise compression and caching |
| 96 | +# Enable WhiteNoise storage |
117 | 97 | STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' |
118 | 98 |
|
119 | | -# ------------------------------------------------------------- |
120 | | -# MEDIA FILES (USER UPLOADS) |
121 | | -# ------------------------------------------------------------- |
122 | | -MEDIA_URL = '/media/' |
123 | | -MEDIA_ROOT = BASE_DIR / 'media' |
124 | | - |
125 | | -# ------------------------------------------------------------- |
126 | | -# DEFAULT AUTO FIELD |
127 | | -# ------------------------------------------------------------- |
128 | | -DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' |
129 | | - |
130 | | -# ------------------------------------------------------------- |
131 | | -# CUSTOM LOGGING (Optional, helps debugging on Render) |
132 | | -# ------------------------------------------------------------- |
133 | | -LOGGING = { |
134 | | - 'version': 1, |
135 | | - 'disable_existing_loggers': False, |
136 | | - 'handlers': { |
137 | | - 'console': {'class': 'logging.StreamHandler'}, |
138 | | - }, |
139 | | - 'root': { |
140 | | - 'handlers': ['console'], |
141 | | - 'level': 'INFO', |
142 | | - }, |
143 | | -} |
144 | | - |
145 | | -# ------------------------------------------------------------- |
146 | | -# YFINANCE / NUMPY USAGE NOTE |
147 | | -# ------------------------------------------------------------- |
148 | | -# You don’t need to configure anything special here. |
149 | | -# Just make sure 'yfinance' and 'numpy' are installed via requirements.txt |
| 99 | +# Default primary key field type |
| 100 | +DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" |
0 commit comments