You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
691 B

1 month ago
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)