TomacGonz commited on
Commit
91970c3
verified
1 Parent(s): 6dd3ce4

Update core/settings.py

Browse files
Files changed (1) hide show
  1. core/settings.py +21 -117
core/settings.py CHANGED
@@ -15,17 +15,17 @@ BASE_DIR = Path(__file__).resolve().parent.parent
15
  SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-yfg#m4w$m&#igix9$bx87f#*gxsd=(l#y_i@ig16-5ug^g3a-k')
16
 
17
  # SECURITY WARNING: don't run with debug turned on in production!
18
- # En Hugging Face, si no pones la variable DEBUG=True en Settings, ser谩 False por defecto.
19
- DEBUG = os.getenv('DEBUG', 'False') == 'True'
20
-
21
- # --- CONFIGURACI脫N DE HOSTS (Crucial para evitar Bad Request) ---
22
- ALLOWED_HOSTS = [
23
- 'localhost',
24
- '127.0.0.1',
25
- '.hf.space', # Para Hugging Face
26
- '.onrender.com', # Para Render (si lo usas)
27
- 'fintech-coop-ai.onrender.com'
28
- ]
29
 
30
  # Application definition
31
  INSTALLED_APPS = [
@@ -42,7 +42,7 @@ INSTALLED_APPS = [
42
  ]
43
 
44
  MIDDLEWARE = [
45
- 'corsheaders.middleware.CorsMiddleware', # Siempre primero
46
  'django.middleware.security.SecurityMiddleware',
47
  'whitenoise.middleware.WhiteNoiseMiddleware',
48
  'django.contrib.sessions.middleware.SessionMiddleware',
@@ -94,121 +94,25 @@ TIME_ZONE = 'UTC'
94
  USE_I18N = True
95
  USE_TZ = True
96
 
97
- # Static files (WhiteNoise)
98
  STATIC_URL = 'static/'
99
  STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
100
- STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
 
101
 
102
  DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
103
 
104
- # --- CONFIGURACI脫N DE CORS (Para conectar con Vercel) ---
105
- CORS_ALLOW_ALL_ORIGINS = True # Permite conexiones desde cualquier origen (Vercel, Local, etc.)
 
106
  CORS_ALLOW_HEADERS = ["*"]
107
 
108
- # --- CONFIGURACI脫N DE CSRF (Para formularios y POST) ---
109
  CSRF_TRUSTED_ORIGINS = [
110
  "https://fintech-coop-ai.vercel.app",
111
  "https://fintech-coop-or6mski9z-tomasgonzalezpy-4881s-projects.vercel.app",
112
  "https://*.hf.space"
113
  ]
114
- TEMPLATES = [
115
- {
116
- 'BACKEND': 'django.template.backends.django.DjangoTemplates',
117
- 'DIRS': [],
118
- 'APP_DIRS': True,
119
- 'OPTIONS': {
120
- 'context_processors': [
121
- 'django.template.context_processors.request',
122
- 'django.contrib.auth.context_processors.auth',
123
- 'django.contrib.messages.context_processors.messages',
124
- ],
125
- },
126
- },
127
- ]
128
-
129
- WSGI_APPLICATION = 'core.wsgi.application'
130
-
131
-
132
- # Database
133
- # https://docs.djangoproject.com/en/5.2/ref/settings/#databases
134
-
135
- DATABASES = {
136
- 'default': {
137
- 'ENGINE': 'django.db.backends.sqlite3',
138
- 'NAME': BASE_DIR / 'db.sqlite3',
139
- }
140
- }
141
-
142
-
143
- # Password validation
144
- # https://docs.djangoproject.com/en/5.2/ref/settings/#auth-password-validators
145
-
146
- AUTH_PASSWORD_VALIDATORS = [
147
- {
148
- 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
149
- },
150
- {
151
- 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
152
- },
153
- {
154
- 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
155
- },
156
- {
157
- 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
158
- },
159
- ]
160
-
161
-
162
- # Internationalization
163
- # https://docs.djangoproject.com/en/5.2/topics/i18n/
164
-
165
- LANGUAGE_CODE = 'en-us'
166
-
167
- TIME_ZONE = 'UTC'
168
-
169
- USE_I18N = True
170
-
171
- USE_TZ = True
172
-
173
-
174
- # Static files (CSS, JavaScript, Images)
175
- # https://docs.djangoproject.com/en/5.2/howto/static-files/
176
-
177
- STATIC_URL = 'static/'
178
-
179
- # Default primary key field type
180
- # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field
181
-
182
- DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
183
-
184
-
185
- CORS_ALLOWED_ORIGINS = [
186
- "http://localhost:3000",
187
- "https://fintech-coop-ai.vercel.app",
188
- "https://fintech-coop-or6mski9z-tomasgonzalezpy-4881s-projects.vercel.app"
189
- ]
190
-
191
- CORS_ALLOW_HEADERS = ["*"]
192
- CORS_ALLOWED_ORIGIN_REGEXES = [
193
- r"^https://.*\.vercel\.app$",
194
- ]
195
-
196
- ALLOWED_HOSTS = [
197
- '*',
198
- '.hf.space',
199
- 'tomacgonz-fintech-coop-api.hf.space',
200
- 'localhost',
201
- '127.0.0.1'
202
- ]
203
-
204
- STATIC_URL = 'static/'
205
- STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
206
- STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
207
-
208
- CSRF_TRUSTED_ORIGINS = [
209
- "https://fintech-coop-ai.vercel.app",
210
- "https://fintech-coop-or6mski9z-tomasgonzalezpy-4881s-projects.vercel.app"
211
- ]
212
 
213
- DEBUG = os.getenv('DEBUG', 'False') == 'True'
214
- ALLOWED_HOSTS = ['localhost', '127.0.0.1', '.onrender.com', 'fintech-coop-ai.onrender.com']
 
15
  SECRET_KEY = os.getenv('SECRET_KEY', 'django-insecure-yfg#m4w$m&#igix9$bx87f#*gxsd=(l#y_i@ig16-5ug^g3a-k')
16
 
17
  # SECURITY WARNING: don't run with debug turned on in production!
18
+ # Forzamos DEBUG a True para que si hay un error, nos diga exactamente qu茅 es en vez de Bad Request
19
+ DEBUG = True
20
+
21
+ # --- CONFIGURACI脫N DE HOSTS ---
22
+ # El '*' es vital para que el proxy de Hugging Face no bloquee la petici贸n
23
+ ALLOWED_HOSTS = ['*']
24
+
25
+ # --- CONFIGURACI脫N DE PROXY (Esto quita el Bad Request en Hugging Face) ---
26
+ USE_X_FORWARDED_HOST = True
27
+ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
28
+ USE_X_FORWARDED_PORT = True
29
 
30
  # Application definition
31
  INSTALLED_APPS = [
 
42
  ]
43
 
44
  MIDDLEWARE = [
45
+ 'corsheaders.middleware.CorsMiddleware', # Debe ser el primero
46
  'django.middleware.security.SecurityMiddleware',
47
  'whitenoise.middleware.WhiteNoiseMiddleware',
48
  'django.contrib.sessions.middleware.SessionMiddleware',
 
94
  USE_I18N = True
95
  USE_TZ = True
96
 
97
+ # Static files
98
  STATIC_URL = 'static/'
99
  STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
100
+ # Simplificamos esto para evitar errores de directorio inexistente
101
+ STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
102
 
103
  DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
104
 
105
+ # --- CONFIGURACI脫N DE CORS ---
106
+ CORS_ALLOW_ALL_ORIGINS = True
107
+ CORS_ALLOW_CREDENTIALS = True
108
  CORS_ALLOW_HEADERS = ["*"]
109
 
110
+ # --- CONFIGURACI脫N DE CSRF ---
111
  CSRF_TRUSTED_ORIGINS = [
112
  "https://fintech-coop-ai.vercel.app",
113
  "https://fintech-coop-or6mski9z-tomasgonzalezpy-4881s-projects.vercel.app",
114
  "https://*.hf.space"
115
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
+ # Evitar que Django fuerce barras diagonales si el cliente no las env铆a
118
+ APPEND_SLASH = True