import os from decouple import config from pathlib import Path from .jazzmin import JAZZMIN_SETTINGS from .rest_framework import REST_FRAMEWORK, SIMPLE_JWT, SPECTACULAR_SETTINGS BASE_DIR = Path(__file__).resolve().parent.parent.parent SECRET_KEY = config("SECRET_KEY", default="unsafe-secret-key") DEBUG = config("DEBUG", cast=bool, default=False) ALLOWED_HOSTS = ["*"] INSTALLED_APPS = [ "jazzmin", # Core Django "django.contrib.admin", "django.contrib.auth", "django.contrib.contenttypes", "django.contrib.sessions", "django.contrib.messages", "django.contrib.staticfiles", # Third-party "rest_framework", "rest_framework_simplejwt", "django_filters", "corsheaders", "drf_spectacular", # Local "apps.accounts", "apps.events", "apps.news", "apps.jobs", "apps.forum", "apps.mentorship", "apps.achievements", "apps.groups", "apps.messaging", "apps.notifications", "apps.dashboard", ] AUTH_USER_MODEL = "accounts.User" AUTHENTICATION_BACKENDS = [ "apps.accounts.backends.EmailOrPhoneBackend", "django.contrib.auth.backends.ModelBackend", ] MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "corsheaders.middleware.CorsMiddleware", # CORS middleware "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", ] ROOT_URLCONF = "config.urls" TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [], "APP_DIRS": True, "OPTIONS": { "context_processors": [ "django.template.context_processors.request", "django.contrib.auth.context_processors.auth", "django.contrib.messages.context_processors.messages", ], }, }, ] WSGI_APPLICATION = "config.wsgi.application" DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": BASE_DIR / "db.sqlite3", } } # Password validation # https://docs.djangoproject.com/en/5.2/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 LANGUAGE_CODE = "en-us" TIME_ZONE = "Asia/Kathmandu" USE_I18N = True USE_TZ = True # Static files (CSS, JavaScript, Images) STATIC_URL = "/static/" # STATICFILES_DIRS = [BASE_DIR / "static"] MEDIA_URL = "/media/" MEDIA_ROOT = BASE_DIR / "media" # REST Framework configuration is imported from rest_framework.py # Default primary key field type DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" # CORS Configuration CORS_ALLOW_ALL_ORIGINS = True # Only for development CORS_ALLOW_CREDENTIALS = True CORS_ALLOWED_ORIGINS = [ "http://localhost:3000", "http://127.0.0.1:3000", ] CORS_ALLOWED_ORIGIN_REGEXES = [ r"^https://\w+\.yourdomain\.com$", ] 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", ] # Security Settings if not DEBUG: SECURE_SSL_REDIRECT = True SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True SECURE_BROWSER_XSS_FILTER = True SECURE_CONTENT_TYPE_NOSNIFF = True X_FRAME_OPTIONS = "DENY" SECURE_HSTS_SECONDS = 31536000 # 1 year SECURE_HSTS_INCLUDE_SUBDOMAINS = True SECURE_HSTS_PRELOAD = True