Browse Source

first commit

master
jc 1 month ago
commit
da905675e7
  1. 26
      app.py
  2. 18
      project-folder/public/insex.html
  3. BIN
      project-folder/public/static/beijing-wildlife.jpg
  4. 18
      project-folder/public/static/index.html
  5. 14
      project-folder/public/static/script.js
  6. 31
      project-folder/public/static/style.css

26
app.py

@ -0,0 +1,26 @@
from flask import Flask, jsonify
app = Flask(__name__, static_folder="public", static_url_path="/static")
# 根路径返回 index.html
@app.route("/")
def serve_index():
return app.send_static_file("index.html")
# API 子路径,提供数据
@app.route("/api/data")
def api_data():
return jsonify({
"message": "Welcome to Beijing Wildlife Park",
"data": [
{"name": "Panda", "description": "Giant panda native to China"},
{"name": "Giraffe", "description": "The tallest land animal"},
{"name": "Elephant", "description": "The largest land animal"}
]
})
if __name__ == "__main__":
app.run(debug=True, port=80)

18
project-folder/public/insex.html

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Beijing Wildlife Park</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<h1>Beijing Wildlife Park</h1>
<img src="/static/beijing-wildlife.jpg" alt="Wildlife in Beijing">
<p>Welcome to Beijing Wildlife Park, home to a variety of animals.</p>
<h2>Animals</h2>
<ul id="animal-list">
<!-- Animal list will be dynamically inserted here -->
</ul>
<script src="/static/script.js"></script>
</body>
</html>

BIN
project-folder/public/static/beijing-wildlife.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 MiB

18
project-folder/public/static/index.html

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Beijing Wildlife Park</title>
<link rel="stylesheet" href="/static/style.css">
</head>
<body>
<h1>Beijing Wildlife Park</h1>
<img src="/static/beijing-wildlife.jpg" alt="Wildlife in Beijing">
<p>Welcome to Beijing Wildlife Park, home to a variety of animals.</p>
<h2>Animals</h2>
<ul id="animal-list">
<!-- Animal list will be dynamically inserted here -->
</ul>
<script src="/static/script.js"></script>
</body>
</html>

14
project-folder/public/static/script.js

@ -0,0 +1,14 @@
document.addEventListener('DOMContentLoaded', function() {
const animals = [
{ name: "Panda", description: "Giant panda native to China" },
{ name: "Giraffe", description: "The tallest land animal" },
{ name: "Elephant", description: "The largest land animal" }
];
const animalListElement = document.getElementById('animal-list');
animals.forEach(animal => {
const li = document.createElement('li');
li.textContent = `${animal.name} - ${animal.description}`;
animalList.appendChild(li);
});
});

31
project-folder/public/static/style.css

@ -0,0 +1,31 @@
body {
font-family: Arial, sans-serif;
background-color: #f8f4f9;
color: #333;
margin: 0;
padding: 20px;
}
h1 {
color: #d4ea;
text-align: center;
}
img {
max-width: 100%;
height: auto;
}
a {
color: #d4ea;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
#animal-list li {
list-style-type: none;
margin-bottom: 10px;
}
Loading…
Cancel
Save