document.addEventListener("DOMContentLoaded", () => { fetch("/api/python-tips") .then(response => response.json()) .then(data => { const tipsList = document.getElementById("tips-list"); data.tips.forEach(tip => { const tipDiv = document.createElement("div"); tipDiv.classList.add("tip"); const tipTitle = document.createElement("h3"); tipTitle.textContent = tip.title; tipDiv.appendChild(tipTitle); const tipDescription = document.createElement("p"); tipDescription.textContent = tip.description; tipDiv.appendChild(tipDescription); const tipExample = document.createElement("pre"); tipExample.textContent = tip.example; tipDiv.appendChild(tipExample); tipsList.appendChild(tipDiv); }); }) .catch(error => { console.error("获取数据时出错:", error); }); });