Skip to content

Commit 6825fcf

Browse files
committed
fix the ALLOWED_HOSTS
1 parent b5ea959 commit 6825fcf

File tree

3 files changed

+55
-11
lines changed

3 files changed

+55
-11
lines changed

check_render_settings.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Script to check Django settings on Render.com
3+
4+
# Activate the virtual environment
5+
source /opt/venv/bin/activate
6+
7+
# Run the settings check script
8+
python check_settings.py
9+
10+
# Exit with success
11+
exit 0

check_settings.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
"""
3+
Simple script to verify Django settings are loaded correctly.
4+
Run this on your Render.com environment to debug settings issues.
5+
"""
6+
import os
7+
import sys
8+
import django
9+
10+
# Set the Django settings module
11+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'socialcal.settings')
12+
13+
# Initialize Django
14+
django.setup()
15+
16+
# Import settings after Django is initialized
17+
from django.conf import settings
18+
19+
# Print key settings for debugging
20+
print("=" * 50)
21+
print("Django Settings Verification")
22+
print("=" * 50)
23+
print(f"DEBUG: {settings.DEBUG}")
24+
print(f"ALLOWED_HOSTS: {settings.ALLOWED_HOSTS}")
25+
print(f"'www.socialcal.io' in ALLOWED_HOSTS: {'www.socialcal.io' in settings.ALLOWED_HOSTS}")
26+
print(f"Environment Variables:")
27+
print(f" RENDER: {os.environ.get('RENDER', 'Not set')}")
28+
print(f" DEBUG: {os.environ.get('DEBUG', 'Not set')}")
29+
print(f" ADDITIONAL_ALLOWED_HOSTS: {os.environ.get('ADDITIONAL_ALLOWED_HOSTS', 'Not set')}")
30+
print("=" * 50)

socialcal/settings.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ def get_env_variable(var_name):
2121
# Set DEBUG based on environment variable, default to True for development
2222
DEBUG = os.environ.get('DEBUG', 'True') == 'True'
2323

24-
# Configure allowed hosts based on environment
25-
if DEBUG and not os.environ.get('RENDER', False):
26-
# Local development
27-
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
28-
else:
29-
# Production environment
30-
ALLOWED_HOSTS = ['socialcal.io', 'www.socialcal.io', 'socialcal.onrender.com']
24+
# Always include critical production domains in ALLOWED_HOSTS
25+
ALLOWED_HOSTS = ['socialcal.io', 'www.socialcal.io', 'socialcal.onrender.com']
26+
27+
# Add development hosts if in debug mode
28+
if DEBUG:
29+
ALLOWED_HOSTS += ['localhost', '127.0.0.1']
3130

32-
# Add any additional domains from environment variable if set
33-
additional_hosts = os.environ.get('ADDITIONAL_ALLOWED_HOSTS', '')
34-
if additional_hosts:
35-
ALLOWED_HOSTS.extend(additional_hosts.split(','))
31+
# Add any additional domains from environment variable if set
32+
additional_hosts = os.environ.get('ADDITIONAL_ALLOWED_HOSTS', '')
33+
if additional_hosts:
34+
ALLOWED_HOSTS.extend(additional_hosts.split(','))
35+
36+
# Print ALLOWED_HOSTS to logs for debugging
37+
print(f"ALLOWED_HOSTS: {ALLOWED_HOSTS}")
38+
print(f"DEBUG: {DEBUG}")
3639

3740
# Modify installed apps based on whether we're testing
3841
INSTALLED_APPS = [

0 commit comments

Comments
 (0)