Update config/settings.py
Browse files- config/settings.py +29 -48
config/settings.py
CHANGED
|
@@ -2,12 +2,6 @@
|
|
| 2 |
Django settings for config project.
|
| 3 |
|
| 4 |
Generated by 'django-admin startproject' using Django 6.0.
|
| 5 |
-
|
| 6 |
-
For more information on this file, see
|
| 7 |
-
https://docs.djangoproject.com/en/6.0/topics/settings/
|
| 8 |
-
|
| 9 |
-
For the full list of settings and their values, see
|
| 10 |
-
https://docs.djangoproject.com/en/6.0/ref/settings/
|
| 11 |
"""
|
| 12 |
|
| 13 |
from pathlib import Path
|
|
@@ -22,17 +16,14 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|
| 22 |
MEDIA_ROOT = BASE_DIR/'myapp'/'media'
|
| 23 |
MEDIA_URL = '/media/'
|
| 24 |
|
|
|
|
| 25 |
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
| 26 |
|
| 27 |
-
# This is the URL used to access media in the browser
|
| 28 |
-
|
| 29 |
-
# Quick-start development settings - unsuitable for production
|
| 30 |
-
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
|
| 31 |
-
|
| 32 |
# SECURITY WARNING: keep the secret key used in production secret!
|
| 33 |
SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-1+*4#52%(ibk-rwry0!q9(%7#il5@+ny1un48d!cp9fe5v=+ir')
|
| 34 |
|
| 35 |
# SECURITY WARNING: don't run with debug turned on in production!
|
|
|
|
| 36 |
DEBUG = False
|
| 37 |
|
| 38 |
ALLOWED_HOSTS = ['*']
|
|
@@ -54,21 +45,40 @@ INSTALLED_APPS = [
|
|
| 54 |
|
| 55 |
MIDDLEWARE = [
|
| 56 |
'django.middleware.security.SecurityMiddleware',
|
| 57 |
-
'whitenoise.middleware.WhiteNoiseMiddleware', #
|
| 58 |
'django.contrib.sessions.middleware.SessionMiddleware',
|
| 59 |
'django.middleware.common.CommonMiddleware',
|
| 60 |
'django.middleware.csrf.CsrfViewMiddleware',
|
| 61 |
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
| 62 |
'django.contrib.messages.middleware.MessageMiddleware',
|
| 63 |
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
| 64 |
-
|
| 65 |
]
|
| 66 |
|
| 67 |
-
#
|
|
|
|
|
|
|
| 68 |
SECURE_SSL_REDIRECT = False
|
| 69 |
-
|
|
|
|
| 70 |
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
SECURE_CONTENT_SECURITY_POLICY = {
|
| 73 |
'default-src': ("'self'",),
|
| 74 |
'script-src': ("'self'", "cdn.tailwindcss.com"),
|
|
@@ -96,8 +106,6 @@ WSGI_APPLICATION = 'config.wsgi.application'
|
|
| 96 |
|
| 97 |
|
| 98 |
# Database
|
| 99 |
-
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases
|
| 100 |
-
|
| 101 |
DATABASES = {
|
| 102 |
'default': {
|
| 103 |
'ENGINE': 'django.db.backends.sqlite3',
|
|
@@ -107,8 +115,6 @@ DATABASES = {
|
|
| 107 |
|
| 108 |
|
| 109 |
# Password validation
|
| 110 |
-
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators
|
| 111 |
-
|
| 112 |
AUTH_PASSWORD_VALIDATORS = [
|
| 113 |
{
|
| 114 |
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
@@ -126,47 +132,22 @@ AUTH_PASSWORD_VALIDATORS = [
|
|
| 126 |
|
| 127 |
|
| 128 |
# Internationalization
|
| 129 |
-
# https://docs.djangoproject.com/en/6.0/topics/i18n/
|
| 130 |
-
|
| 131 |
LANGUAGE_CODE = 'en-us'
|
| 132 |
-
|
| 133 |
TIME_ZONE = 'UTC'
|
| 134 |
-
|
| 135 |
USE_I18N = True
|
| 136 |
-
|
| 137 |
USE_TZ = True
|
| 138 |
|
| 139 |
|
| 140 |
# --- STATIC FILES CONFIGURATION ---
|
| 141 |
STATIC_URL = 'static/'
|
| 142 |
|
| 143 |
-
#
|
| 144 |
STATICFILES_DIRS = [
|
| 145 |
-
BASE_DIR / "static",
|
| 146 |
BASE_DIR / "assets",
|
| 147 |
BASE_DIR / "css",
|
| 148 |
BASE_DIR / "js",
|
| 149 |
]
|
| 150 |
|
| 151 |
-
#
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
# Tambahkan ini agar Whitenoise bekerja maksimal
|
| 155 |
-
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
# 1. Izinkan website tampil di dalam frame Hugging Face
|
| 159 |
-
X_FRAME_OPTIONS = 'ALLOWALL'
|
| 160 |
-
|
| 161 |
-
# Tambahkan domain spesifik space agar upload lancar
|
| 162 |
-
CSRF_TRUSTED_ORIGINS = [
|
| 163 |
-
'https://pcd2025-irkham.hf.space', # Link unik space kamu
|
| 164 |
-
'https://*.hf.space',
|
| 165 |
-
'https://huggingface.co'
|
| 166 |
-
]
|
| 167 |
-
|
| 168 |
-
# Tambahkan baris ini agar Cookie keamanan bisa dikirim lewat iframe Hugging Face
|
| 169 |
-
CSRF_COOKIE_SAMESITE = 'None'
|
| 170 |
-
CSRF_COOKIE_SECURE = True
|
| 171 |
-
SESSION_COOKIE_SAMESITE = 'None'
|
| 172 |
-
SESSION_COOKIE_SECURE = True
|
|
|
|
| 2 |
Django settings for config project.
|
| 3 |
|
| 4 |
Generated by 'django-admin startproject' using Django 6.0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
"""
|
| 6 |
|
| 7 |
from pathlib import Path
|
|
|
|
| 16 |
MEDIA_ROOT = BASE_DIR/'myapp'/'media'
|
| 17 |
MEDIA_URL = '/media/'
|
| 18 |
|
| 19 |
+
# Lokasi pengumpulan file statis untuk production
|
| 20 |
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# SECURITY WARNING: keep the secret key used in production secret!
|
| 23 |
SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-1+*4#52%(ibk-rwry0!q9(%7#il5@+ny1un48d!cp9fe5v=+ir')
|
| 24 |
|
| 25 |
# SECURITY WARNING: don't run with debug turned on in production!
|
| 26 |
+
# Dimatikan agar lebih stabil di Hugging Face
|
| 27 |
DEBUG = False
|
| 28 |
|
| 29 |
ALLOWED_HOSTS = ['*']
|
|
|
|
| 45 |
|
| 46 |
MIDDLEWARE = [
|
| 47 |
'django.middleware.security.SecurityMiddleware',
|
| 48 |
+
'whitenoise.middleware.WhiteNoiseMiddleware', # Untuk melayani file statis
|
| 49 |
'django.contrib.sessions.middleware.SessionMiddleware',
|
| 50 |
'django.middleware.common.CommonMiddleware',
|
| 51 |
'django.middleware.csrf.CsrfViewMiddleware',
|
| 52 |
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
| 53 |
'django.contrib.messages.middleware.MessageMiddleware',
|
| 54 |
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
|
|
| 55 |
]
|
| 56 |
|
| 57 |
+
# --- PENGATURAN KEAMANAN FINAL (SOLUSI REDIRECT LOOP & CSRF) ---
|
| 58 |
+
|
| 59 |
+
# Wajib False di Hugging Face agar tidak terjadi "Too many redirects"
|
| 60 |
SECURE_SSL_REDIRECT = False
|
| 61 |
+
|
| 62 |
+
# Memberitahu Django bahwa Hugging Face menggunakan HTTPS (Kunci Utama)
|
| 63 |
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
|
| 64 |
|
| 65 |
+
# Pengaturan Cookie agar bisa menembus Iframe Hugging Face
|
| 66 |
+
SESSION_COOKIE_SECURE = True
|
| 67 |
+
CSRF_COOKIE_SECURE = True
|
| 68 |
+
SESSION_COOKIE_SAMESITE = 'None'
|
| 69 |
+
CSRF_COOKIE_SAMESITE = 'None'
|
| 70 |
+
|
| 71 |
+
# Izinkan website tampil di dalam frame Hugging Face
|
| 72 |
+
X_FRAME_OPTIONS = 'ALLOWALL'
|
| 73 |
+
|
| 74 |
+
# Daftar domain terpercaya untuk formulir/upload
|
| 75 |
+
CSRF_TRUSTED_ORIGINS = [
|
| 76 |
+
'https://pcd2025-irkham.hf.space',
|
| 77 |
+
'https://*.hf.space',
|
| 78 |
+
'https://huggingface.co'
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
SECURE_BROWSER_XSS_FILTER = True
|
| 82 |
SECURE_CONTENT_SECURITY_POLICY = {
|
| 83 |
'default-src': ("'self'",),
|
| 84 |
'script-src': ("'self'", "cdn.tailwindcss.com"),
|
|
|
|
| 106 |
|
| 107 |
|
| 108 |
# Database
|
|
|
|
|
|
|
| 109 |
DATABASES = {
|
| 110 |
'default': {
|
| 111 |
'ENGINE': 'django.db.backends.sqlite3',
|
|
|
|
| 115 |
|
| 116 |
|
| 117 |
# Password validation
|
|
|
|
|
|
|
| 118 |
AUTH_PASSWORD_VALIDATORS = [
|
| 119 |
{
|
| 120 |
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
|
|
|
|
| 132 |
|
| 133 |
|
| 134 |
# Internationalization
|
|
|
|
|
|
|
| 135 |
LANGUAGE_CODE = 'en-us'
|
|
|
|
| 136 |
TIME_ZONE = 'UTC'
|
|
|
|
| 137 |
USE_I18N = True
|
|
|
|
| 138 |
USE_TZ = True
|
| 139 |
|
| 140 |
|
| 141 |
# --- STATIC FILES CONFIGURATION ---
|
| 142 |
STATIC_URL = 'static/'
|
| 143 |
|
| 144 |
+
# Folder sumber file statis
|
| 145 |
STATICFILES_DIRS = [
|
| 146 |
+
BASE_DIR / "static",
|
| 147 |
BASE_DIR / "assets",
|
| 148 |
BASE_DIR / "css",
|
| 149 |
BASE_DIR / "js",
|
| 150 |
]
|
| 151 |
|
| 152 |
+
# Menggunakan storage dari Whitenoise agar CSS muncul sempurna
|
| 153 |
+
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|