settings
settings
load_dotenv()
OPENAI_API_KEY = os.getenv('OPENAI_API_KEY')
ALLOWED_HOSTS = [
'localhost',
'127.0.0.1',
'[::1]',
'.amazonaws.com',
'python.jeebuddy.in',
'python-backend-env-1.eba-5hzqwm2u.ap-south-1.elasticbeanstalk.com', # No
trailing slash
]
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'corsheaders',
'main',
'user',
'subscription',
]
ASGI_APPLICATION = 'config.asgi.application'
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
],
}
# CORS settings
CORS_ALLOW_ALL_ORIGINS = True # Ensure that only specific origins are allowed
CORS_ALLOWED_ORIGINS = [
"https://python.jeebuddy.in", # Your production backend domain
"https://www.jeebuddy.in", # Your website's domain that is sending the
requests
"http://localhost:5173", # Include your local frontend if needed
]
CORS_ALLOW_CREDENTIALS = True # Enable credentials if required (e.g., when sending
cookies/authorization headers)
CORS_ALLOW_METHODS = [
"DELETE",
"GET",
"OPTIONS",
"PATCH",
"POST",
"PUT",
]
CORS_ALLOW_HEADERS = [
"accept",
"accept-encoding",
"authorization",
"content-type",
"dnt",
"origin",
"user-agent",
"x-csrftoken",
"x-requested-with",
]
ROOT_URLCONF = 'core.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'core.wsgi.application'
# Database
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql',
# 'NAME': os.getenv('SUPABASE_DB_NAME', 'postgres'),
# 'USER': os.getenv('SUPABASE_DB_USER', 'postgres'),
# 'PASSWORD': os.getenv('SUPABASE_DB_PASSWORD'),
# 'HOST': os.getenv('SUPABASE_DB_HOST'),
# 'PORT': os.getenv('SUPABASE_DB_PORT', '5432'),
# 'OPTIONS': {
# 'sslmode': 'require' if os.getenv('DATABASE_SSL_REQUIRE',
'true').lower() == 'true' else 'disable',
# }
# }
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv('SUPABASE_DB_NAME'),
'USER': os.getenv('SUPABASE_DB_USER'),
'PASSWORD': os.getenv('SUPABASE_DB_PASSWORD'),
'HOST': os.getenv('SUPABASE_DB_HOST'),
'PORT': os.getenv('SUPABASE_DB_PORT'),
'OPTIONS': {
'sslmode': 'require', # Ensure SSL mode is enabled
},
}
}
# Password validation
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME':
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/5.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Static files
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# Security settings
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True