Spaces:
Runtime error
Runtime error
Download settings.py from OLETECH/BUSINESSTRACKER: direct link, hf CLI and curl.
- Browser
- Download file 4.51 kB
-
https://huggingface.co/spaces/OLETECH/BUSINESSTRACKER/resolve/main/settings.py
- Command line
-
hf download hf://spaces/OLETECH/BUSINESSTRACKER/settings.py
-
curl -L -o settings.py https://huggingface.co/spaces/OLETECH/BUSINESSTRACKER/resolve/main/settings.py
4.51 kB
| from pathlib import Path | |
| from datetime import timedelta | |
| import os | |
| import dj_database_url | |
| from dotenv import load_dotenv | |
| # Load local .env if it exists | |
| load_dotenv() | |
| # BASE_DIR points to the root where manage.py is | |
| BASE_DIR = Path(__file__).resolve().parent | |
| # --- SECURITY --- | |
| SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-local-dev-key-change-me') | |
| DEBUG = os.getenv('DEBUG', 'False') == 'True' # Recommended False for production | |
| ALLOWED_HOSTS = ['*'] | |
| # --- APPS --- | |
| INSTALLED_APPS = [ | |
| 'django.contrib.admin', | |
| 'django.contrib.auth', | |
| 'django.contrib.contenttypes', | |
| 'django.contrib.sessions', | |
| 'django.contrib.messages', | |
| 'django.contrib.staticfiles', | |
| 'rest_framework', | |
| 'rest_framework_simplejwt', | |
| 'corsheaders', | |
| 'whitenoise.runserver_nostatic', | |
| 'users', | |
| 'dashboard', | |
| 'invoices', | |
| 'receipts', | |
| 'inventory', | |
| 'reports', | |
| ] | |
| # --- MIDDLEWARE --- | |
| 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', | |
| ] | |
| ROOT_URLCONF = '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 = 'wsgi.application' | |
| # --- DATABASE (Optimized for Supabase Pooler Port 6543) --- | |
| DATABASE_URL = os.environ.get('DATABASE_URL') | |
| if DATABASE_URL: | |
| DATABASES = { | |
| 'default': dj_database_url.config( | |
| default=DATABASE_URL, | |
| conn_max_age=0, # Set to 0 for Transaction Pooling | |
| ssl_require=True | |
| ) | |
| } | |
| else: | |
| DATABASES = { | |
| 'default': { | |
| 'ENGINE': 'django.db.backends.sqlite3', | |
| 'NAME': BASE_DIR / 'db.sqlite3', | |
| } | |
| } | |
| # --- AUTHENTICATION --- | |
| AUTH_USER_MODEL = 'users.CustomUser' | |
| REST_FRAMEWORK = { | |
| 'DEFAULT_AUTHENTICATION_CLASSES': ( | |
| 'rest_framework_simplejwt.authentication.JWTAuthentication', | |
| ), | |
| 'DEFAULT_PERMISSION_CLASSES': ( | |
| 'rest_framework.permissions.IsAuthenticated', | |
| ), | |
| } | |
| SIMPLE_JWT = { | |
| 'ACCESS_TOKEN_LIFETIME': timedelta(days=1), | |
| 'REFRESH_TOKEN_LIFETIME': timedelta(days=7), | |
| 'AUTH_HEADER_TYPES': ('Bearer',), | |
| } | |
| # --- CORS & TRAFFIC --- | |
| CORS_ALLOWED_ORIGINS = [ | |
| "https://business-tracker-lake.vercel.app", | |
| "http://localhost:5173", | |
| "http://localhost:3000", | |
| ] | |
| # --- HUGGING FACE SECURITY FIXES --- | |
| CSRF_TRUSTED_ORIGINS = [ | |
| 'https://*.hf.space', | |
| 'https://*.huggingface.co', | |
| "https://business-tracker-lake.vercel.app" | |
| ] | |
| # Allow the site to be displayed in the Hugging Face Iframe | |
| X_FRAME_OPTIONS = 'ALLOWALL' | |
| SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') | |
| USE_X_FORWARDED_HOST = True | |
| USE_X_FORWARDED_PORT = True | |
| # Ensure cookies work across the Hugging Face domain | |
| SESSION_COOKIE_SAMESITE = 'None' | |
| SESSION_COOKIE_SECURE = True | |
| CSRF_COOKIE_SAMESITE = 'None' | |
| CSRF_COOKIE_SECURE = True | |
| # --- STATIC FILES --- | |
| STATIC_URL = '/static/' | |
| STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') | |
| STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' | |
| # --- INTERNATIONALIZATION --- | |
| LANGUAGE_CODE = 'en-us' | |
| TIME_ZONE = 'Africa/Kampala' | |
| USE_I18N = True | |
| USE_TZ = True | |
| DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' | |
| # --- EMAIL SETTINGS --- | |
| EMAIL_BACKEND = os.getenv('EMAIL_BACKEND', 'django.core.mail.backends.smtp.EmailBackend') | |
| EMAIL_HOST = os.getenv('EMAIL_HOST', 'smtp.gmail.com') | |
| EMAIL_PORT = int(os.getenv('EMAIL_PORT', 587) if os.getenv('EMAIL_PORT') else 587) | |
| EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS', 'True') == 'True' | |
| EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER') | |
| EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD') | |
| DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', EMAIL_HOST_USER) | |
| ALERT_EMAIL = os.getenv('ALERT_EMAIL', EMAIL_HOST_USER) |