check_real_template.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """检查实际模板内容和预览结果"""
  2. import requests
  3. API_BASE = "http://localhost:8000/api"
  4. # 获取所有模板
  5. response = requests.get(f"{API_BASE}/templates")
  6. templates = response.json()
  7. # 找一个有template_body的原创模板
  8. template = None
  9. for tpl in templates:
  10. if tpl.get('template_body') and not tpl.get('reusable_from'):
  11. template = tpl
  12. break
  13. if not template:
  14. print("❌ 没有找到原创模板")
  15. exit(1)
  16. print(f"✅ 模板: {template['machine_model']}/{template['template_type']}")
  17. print(f" ID: {template['id'][:12]}...")
  18. print()
  19. print("=" * 80)
  20. print("📝 模板正文(前500字符):")
  21. print("=" * 80)
  22. print(template['template_body'][:500])
  23. print()
  24. # 预览
  25. print("=" * 80)
  26. print("🔍 预览结果:")
  27. print("=" * 80)
  28. response = requests.post(f"{API_BASE}/templates/preview", json={
  29. "template_body": template['template_body']
  30. })
  31. result = response.json()
  32. if result.get('success'):
  33. print(result.get('result', ''))
  34. else:
  35. print(f"❌ 错误: {result.get('error')}")
  36. print()
  37. print("=" * 80)
  38. print("📊 变量列表:")
  39. print("=" * 80)
  40. for v in result.get('variables', []):
  41. print(f" {v['name']}: {v['value']}")