fix: robust HTML delivery for downloads section
- Decoupled downloads container from main template to prevent static rendering errors - Forced HTMX polling to use html=1 parameter - Added server-side debug logging for request format detection - Fixed Jinja2 loop error by ensuring tasks are provided via HTMX
This commit is contained in:
@@ -27,14 +27,15 @@ async def get_downloads(
|
||||
"""Get list of all download tasks. Returns HTML for HTMX."""
|
||||
tasks = download_manager.get_all_tasks()
|
||||
|
||||
# Check for HTMX or explicit HTML request
|
||||
# Force HTML if requested or via HTMX
|
||||
if html or request.headers.get("HX-Request"):
|
||||
print(f"[DOWNLOADS] Returning HTML list for {len(tasks)} tasks")
|
||||
print(f"[DOWNLOADS] HTMX Request detected. Returning HTML for {len(tasks)} tasks.")
|
||||
return templates.TemplateResponse(
|
||||
"components/downloads_list.html",
|
||||
{"request": request, "tasks": tasks}
|
||||
)
|
||||
|
||||
print(f"[DOWNLOADS] API Request detected. Returning JSON.")
|
||||
return {"downloads": tasks}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user