Browse Source

first commit

master
jc 1 month ago
commit
a50db20eaa
  1. 21
      app.py
  2. BIN
      public/images/comb.jpg
  3. 19
      public/index.html
  4. 19
      public/script.js
  5. 57
      public/style.css

21
app.py

@ -0,0 +1,21 @@
from flask import Flask, jsonify, send_from_directory
app = Flask(__name__, static_folder="public", static_url_path="")
@app.route("/")
def serve_index():
return send_from_directory(app.static_folder, "index.html")
@app.route("/api/data")
def api_data():
data = {
"product_name": "古新枣木梳",
"description": "采用古新枣木手工打造,质地坚硬,纹理美观,传承千年工艺。",
"benefits": [
"天然材质,温和护发",
"手工雕刻,工艺精湛",
"传承文化,寓意吉祥"
],
"price": "¥99",
"image_url": "/images/comb.jpg"
}
return jsonify(data)
if __name__ == "__main__":
app.run(debug=True, port=80)

BIN
public/images/comb.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 978 KiB

19
public/index.html

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>古新枣木梳</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1 id="product-name"></h1>
<img id="product-image" class="product-image" src="" alt="古新枣木梳">
<p id="description"></p>
<ul id="benefits" class="benefits"></ul>
<p id="price" class="price"></p>
</div>
<script src="script.js"></script>
</body>
</html>

19
public/script.js

@ -0,0 +1,19 @@
document.addEventListener("DOMContentLoaded", () => {
fetch("/api/data")
.then(response => response.json())
.then(data => {
document.getElementById("product-name").innerText = data.product_name;
document.getElementById("product-image").src = data.image_url;
document.getElementById("description").innerText = data.description;
const benefitsList = document.getElementById("benefits");
data.benefits.forEach(benefit => {
const li = document.createElement("li");
li.innerText = benefit;
benefitsList.appendChild(li);
});
document.getElementById("price").innerText = data.price;
})
.catch(error => {
console.error("Error fetching data:", error);
});
});

57
public/style.css

@ -0,0 +1,57 @@
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
width: 80%;
max-width: 600px;
}
h1 {
color: #333;
}
.product-image {
width: 100%;
height: auto;
border-radius: 10px;
margin: 20px 0;
}
p {
color: #666;
font-size: 16px;
line-height: 1.5;
}
.benefits {
list-style: none;
padding: 0;
}
.benefits li {
background: #e0e0e0;
margin: 10px 0;
padding: 10px;
border-radius: 5px;
color: #333;
font-size: 14px;
}
.price {
color: #ff5722;
font-size: 24px;
font-weight: bold;
}
Loading…
Cancel
Save