Download config/settings.py from pcd2025/irkham: direct link, hf CLI and curl.
- Browser
- Download file 4.08 kB
-
https://huggingface.co/spaces/pcd2025/irkham/resolve/main/config/settings.py
- Command line
-
hf download hf://spaces/pcd2025/irkham/config/settings.py
-
curl -L -o settings.py https://huggingface.co/spaces/pcd2025/irkham/resolve/main/config/settings.py
4.08 kB
| """ | |
| Django settings for config project. | |
| Generated by 'django-admin startproject' using Django 6.0. | |
| """ | |
| from pathlib import Path | |
| import os | |
| from dotenv import load_dotenv | |
| # Load environment variables from .env file | |
| load_dotenv() | |
| # Build paths inside the project like this: BASE_DIR / 'subdir'. | |
| BASE_DIR = Path(__file__).resolve().parent.parent | |
| MEDIA_ROOT = BASE_DIR/'myapp'/'media' | |
| MEDIA_URL = '/media/' | |
| # Lokasi pengumpulan file statis untuk production | |
| STATIC_ROOT = BASE_DIR / 'staticfiles' | |
| # SECURITY WARNING: keep the secret key used in production secret! | |
| SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-1+*4#52%(ibk-rwry0!q9(%7#il5@+ny1un48d!cp9fe5v=+ir') | |
| # SECURITY WARNING: don't run with debug turned on in production! | |
| # Dimatikan agar lebih stabil di Hugging Face | |
| DEBUG = False | |
| ALLOWED_HOSTS = ['*'] | |
| # Application definition | |
| INSTALLED_APPS = [ | |
| 'django.contrib.auth', | |
| 'django.contrib.contenttypes', | |
| 'django.contrib.sessions', | |
| 'django.contrib.admin', | |
| 'django.contrib.messages', | |
| 'django.contrib.staticfiles', | |
| 'rest_framework', | |
| 'myapp', | |
| ] | |
| MIDDLEWARE = [ | |
| 'django.middleware.security.SecurityMiddleware', | |
| 'whitenoise.middleware.WhiteNoiseMiddleware', # Untuk melayani file statis | |
| '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', | |
| ] | |
| # --- PENGATURAN KEAMANAN FINAL (SOLUSI REDIRECT LOOP & CSRF) --- | |
| # Wajib False di Hugging Face agar tidak terjadi "Too many redirects" | |
| SECURE_SSL_REDIRECT = False | |
| # Memberitahu Django bahwa Hugging Face menggunakan HTTPS (Kunci Utama) | |
| SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') | |
| # Pengaturan Cookie agar bisa menembus Iframe Hugging Face | |
| SESSION_COOKIE_SECURE = True | |
| CSRF_COOKIE_SECURE = True | |
| SESSION_COOKIE_SAMESITE = 'None' | |
| CSRF_COOKIE_SAMESITE = 'None' | |
| # Izinkan website tampil di dalam frame Hugging Face | |
| X_FRAME_OPTIONS = 'ALLOWALL' | |
| # Daftar domain terpercaya untuk formulir/upload | |
| CSRF_TRUSTED_ORIGINS = [ | |
| 'https://pcd2025-irkham.hf.space', | |
| 'https://*.hf.space', | |
| 'https://huggingface.co' | |
| ] | |
| SECURE_BROWSER_XSS_FILTER = True | |
| SECURE_CONTENT_SECURITY_POLICY = { | |
| 'default-src': ("'self'",), | |
| 'script-src': ("'self'", "cdn.tailwindcss.com"), | |
| 'style-src': ("'self'", "cdn.tailwindcss.com", "'unsafe-inline'"), | |
| } | |
| 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' | |
| # Database | |
| DATABASES = { | |
| 'default': { | |
| 'ENGINE': 'django.db.backends.sqlite3', | |
| 'NAME': BASE_DIR / 'db.sqlite3', | |
| } | |
| } | |
| # Password validation | |
| 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 = 'UTC' | |
| USE_I18N = True | |
| USE_TZ = True | |
| # --- STATIC FILES CONFIGURATION --- | |
| STATIC_URL = 'static/' | |
| # Folder sumber file statis | |
| STATICFILES_DIRS = [ | |
| BASE_DIR / "static", | |
| BASE_DIR / "assets", | |
| BASE_DIR / "css", | |
| BASE_DIR / "js", | |
| ] | |
| # Menggunakan storage dari Whitenoise agar CSS muncul sempurna | |
| STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' |