1515def debug_media (request ):
1616 """Diagnostic endpoint to check media files."""
1717 import subprocess
18+
1819 result = {
1920 "MEDIA_ROOT" : str (settings .MEDIA_ROOT ),
2021 "MEDIA_ROOT_exists" : os .path .exists (settings .MEDIA_ROOT ),
@@ -29,7 +30,9 @@ def debug_media(request):
2930 for f in filenames [:20 ]: # Limit to first 20
3031 files .append (os .path .join (root , f ).replace (settings .MEDIA_ROOT , "" ))
3132 result ["files" ] = files
32- result ["file_count" ] = sum (len (f ) for _ , _ , f in os .walk (settings .MEDIA_ROOT ))
33+ result ["file_count" ] = sum (
34+ len (f ) for _ , _ , f in os .walk (settings .MEDIA_ROOT )
35+ )
3336 except Exception as e :
3437 result ["error" ] = str (e )
3538 else :
@@ -39,10 +42,13 @@ def debug_media(request):
3942 teleband_media = os .path .join (os .getcwd (), "teleband" , "media" )
4043 result ["teleband_media_exists" ] = os .path .exists (teleband_media )
4144 if os .path .exists (teleband_media ):
42- result ["teleband_media_count" ] = sum (len (f ) for _ , _ , f in os .walk (teleband_media ))
45+ result ["teleband_media_count" ] = sum (
46+ len (f ) for _ , _ , f in os .walk (teleband_media )
47+ )
4348
4449 return JsonResponse (result )
4550
51+
4652urlpatterns = [
4753 path ("" , TemplateView .as_view (template_name = "pages/home.html" ), name = "home" ),
4854 path ("debug-media/" , debug_media , name = "debug-media" ),
@@ -68,9 +74,11 @@ def debug_media(request):
6874# Serve media files - in production with S3 this is handled by S3,
6975# but for Railway/local deployments we serve from filesystem
7076# Note: static() only works with DEBUG=True, so we use serve() directly for non-S3 deployments
71- if not hasattr (settings , 'DEFAULT_FILE_STORAGE' ) or 'S3' not in getattr (settings , 'DEFAULT_FILE_STORAGE' , '' ):
77+ if not hasattr (settings , "DEFAULT_FILE_STORAGE" ) or "S3" not in getattr (
78+ settings , "DEFAULT_FILE_STORAGE" , ""
79+ ):
7280 urlpatterns += [
73- re_path (r' ^media/(?P<path>.*)$' , serve , {' document_root' : settings .MEDIA_ROOT }),
81+ re_path (r" ^media/(?P<path>.*)$" , serve , {" document_root" : settings .MEDIA_ROOT }),
7482 ]
7583
7684if settings .DEBUG :
0 commit comments