Files
crypto_monitor/scripts/diag_render_pages.py
T
dekun efe7a57e60 fix: trade_policy 宏使用 with context 修复 500
Jinja imported macros did not receive trade_policy from render context, causing Internal Server Error on all instance pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-05 00:36:06 +08:00

36 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""Diagnose page render errors (run inside instance dir with venv)."""
from __future__ import annotations
import os
import sys
import traceback
def main() -> int:
inst = sys.argv[1] if len(sys.argv) > 1 else "crypto_monitor_binance"
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.chdir(os.path.join(root, inst))
sys.path.insert(0, os.getcwd())
from app import app # noqa: WPS433
paths = ["/trade", "/key_monitor", "/strategy", "/login"]
with app.test_client() as client:
with client.session_transaction() as sess:
sess["logged_in"] = True
for path in paths:
try:
resp = client.get(path)
print(f"{inst} {path} -> {resp.status_code}")
if resp.status_code >= 400:
body = resp.get_data(as_text=True)
print(body[:3000])
except Exception:
print(f"{inst} {path} -> EXCEPTION")
traceback.print_exc()
return 0
if __name__ == "__main__":
raise SystemExit(main())