Skip to content

Commit 1a586bd

Browse files
authored
Update settings.py
1 parent d2b7d1f commit 1a586bd

File tree

1 file changed

+61
-110
lines changed

1 file changed

+61
-110
lines changed

settings.py

Lines changed: 61 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,100 @@
11
import os
22
from pathlib import Path
3-
import dj_database_url
3+
import dj_database_url # Make sure this is imported
44

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

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')
1611

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
2023
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
2831
]
2932

30-
# -------------------------------------------------------------
31-
# MIDDLEWARE
32-
# -------------------------------------------------------------
3333
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
3736
'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",
4543
]
4644

47-
# -------------------------------------------------------------
48-
# URL CONFIGURATION
49-
# -------------------------------------------------------------
50-
ROOT_URLCONF = 'your_project_name.urls'
45+
ROOT_URLCONF = "ons_trading.urls" # Corrected from your_project_name
5146

52-
# -------------------------------------------------------------
53-
# TEMPLATES
54-
# -------------------------------------------------------------
5547
TEMPLATES = [
5648
{
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",
6658
],
6759
},
6860
},
6961
]
7062

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
7564

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
8068
DATABASES = {
8169
'default': dj_database_url.config(
70+
# Use SQLite locally if DATABASE_URL is not set
8271
default=f'sqlite:///{BASE_DIR / "db.sqlite3"}',
8372
conn_max_age=600,
8473
)
8574
}
8675

87-
# -------------------------------------------------------------
88-
# PASSWORD VALIDATION
89-
# -------------------------------------------------------------
76+
# Password validation
9077
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",},
9582
]
9683

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'
10287
USE_I18N = True
10388
USE_TZ = True
10489

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
10994
STATIC_ROOT = BASE_DIR / 'staticfiles'
11095

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
11797
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
11898

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

Comments
 (0)