Repository navigation
Expand file tree
/
Copy pathdebug_static_files.py
More file actions
98 lines (83 loc) · 2.76 KB
/
Copy pathdebug_static_files.py
File metadata and controls
98 lines (83 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
"""
Debug script for static files issues on Render
Run this on your Render instance via Shell to diagnose issues
"""
import os
import sys
import django
# Setup Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings')
django.setup()
from django.conf import settings
from pathlib import Path
from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage
print("=== STATIC FILES DEBUGGING ===\n")
# Basic settings
print("1. Basic Configuration:")
print(f" DEBUG: {settings.DEBUG}")
print(f" STATIC_URL: {settings.STATIC_URL}")
print(f" STATIC_ROOT: {settings.STATIC_ROOT}")
print(f" STATICFILES_DIRS: {settings.STATICFILES_DIRS}")
print()
# Environment
print("2. Environment:")
print(f" Is Render: {'RENDER' in os.environ}")
print(f" Python version: {sys.version}")
print(f" Django version: {django.VERSION}")
print()
# WhiteNoise check
print("3. WhiteNoise Configuration:")
try:
import whitenoise
print(f" WhiteNoise version: {whitenoise.__version__}")
except ImportError:
print(" WhiteNoise: NOT INSTALLED!")
print(f" WhiteNoise in middleware: {'whitenoise.middleware.WhiteNoiseMiddleware' in settings.MIDDLEWARE}")
print(f" Storage backend: {staticfiles_storage.__class__.__name__}")
print()
# Static files existence
print("4. Static Files Check:")
static_root = Path(settings.STATIC_ROOT)
print(f" Static root exists: {static_root.exists()}")
print(f" Static root is directory: {static_root.is_dir()}")
if static_root.exists() and static_root.is_dir():
css_files = list(static_root.rglob('*.css'))
print(f" Total CSS files: {len(css_files)}")
if css_files:
print(" Sample CSS files:")
for f in css_files[:5]:
print(f" - {f.relative_to(static_root)}")
else:
print(" WARNING: Static root doesn't exist or isn't a directory!")
print()
# Test specific file
print("5. Testing auth.css:")
auth_css = static_root / 'css' / 'auth.css'
print(f" File exists: {auth_css.exists()}")
print(f" File path: {auth_css}")
# Test URL generation
from django.templatetags.static import static
try:
url = static('css/auth.css')
print(f" Generated URL: {url}")
except Exception as e:
print(f" ERROR generating URL: {e}")
# Test finder
found = finders.find('css/auth.css')
print(f" Found by finder: {found is not None}")
if found:
print(f" Finder path: {found}")
print()
# Storage test
print("6. Storage Test:")
try:
exists = staticfiles_storage.exists('css/auth.css')
print(f" Storage says file exists: {exists}")
if exists:
url = staticfiles_storage.url('css/auth.css')
print(f" Storage URL: {url}")
except Exception as e:
print(f" Storage error: {e}")
print("\n=== END DEBUG ===")