Browse Source

first commit

master
jc 1 month ago
commit
2ecf62e88b
  1. 31
      app.py
  2. 28
      public/index.html
  3. 40
      public/script.js
  4. 46
      public/styles.css

31
app.py

@ -0,0 +1,31 @@
from flask import Flask, jsonify, send_from_directory
app = Flask(__name__, static_folder="public", static_url_path="")
# 根路径返回 index.html
@app.route("/")
def serve_index():
return send_from_directory(app.static_folder, "index.html")
# API 子路径,提供《哪吒2》的宣传数据
@app.route("/api/nezha2")
def api_nezha2():
nezha2_data = {
"message": "《哪吒2》宣传信息",
"data": {
"title": "《哪吒2》",
"description": "《哪吒2》是继《哪吒之魔童降世》后的续作,讲述了哪吒的全新冒险故事。",
"trailer_url": "https://www.bilibili.com/video/BV11McieTEN5/", # 替换为实际预告片链接
"cast": [
{"name": "哪吒", "role": "主角", "description": "勇敢无畏的少年英雄"},
{"name": "敖丙", "role": "配角", "description": "哪吒的挚友与对手"},
{"name": "太乙真人", "role": "配角", "description": "哪吒的师父,搞笑又神秘"}
],
"release_date": "2025年12月25日",
"rating": "PG-13"
}
}
return jsonify(nezha2_data)
if __name__ == "__main__":
app.run(debug=True, port=80)

28
public/index.html

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>《哪吒2》宣传网页</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1 id="title">《哪吒2》</h1>
<p id="description"></p>
<div class="trailer">
<h2>预告片</h2>
<iframe id="trailer-iframe" width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>
</div>
<div class="cast">
<h2>主演介绍</h2>
<div id="cast-container"></div>
</div>
<div class="info">
<p><strong>上映日期:</strong><span id="release-date"></span></p>
<p><strong>分级:</strong><span id="rating"></span></p>
</div>
</div>
<script src="script.js"></script>
</body>
</html>

40
public/script.js

@ -0,0 +1,40 @@
document.addEventListener("DOMContentLoaded", function () {
fetch("/api/nezha2")
.then(response => response.json())
.then(data => {
const movieData = data.data;
// 设置标题和描述
document.getElementById("title").textContent = movieData.title;
document.getElementById("description").textContent = movieData.description;
// 设置预告片链接
const trailerIframe = document.getElementById("trailer-iframe");
trailerIframe.src = movieData.trailer_url;
// 渲染主演介绍
const castContainer = document.getElementById("cast-container");
movieData.cast.forEach(cast => {
const castItem = document.createElement("div");
castItem.classList.add("cast-item");
const castName = document.createElement("div");
castName.textContent = `${cast.name} - ${cast.role}`;
const castDescription = document.createElement("div");
castDescription.textContent = cast.description;
castItem.appendChild(castName);
castItem.appendChild(castDescription);
castContainer.appendChild(castItem);
});
// 设置上映日期和分级
document.getElementById("release-date").textContent = movieData.release_date;
document.getElementById("rating").textContent = movieData.rating;
})
.catch(error => {
console.error("Error fetching movie data:", error);
});
});

46
public/styles.css

@ -0,0 +1,46 @@
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
}
.container {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background: #fff;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
h1, h2 {
text-align: center;
color: #333;
}
.trailer iframe {
display: block;
margin: 20px auto;
border-radius: 8px;
}
.cast {
margin-top: 20px;
}
.cast-item {
margin-bottom: 10px;
padding: 10px;
border-bottom: 1px solid #ddd;
}
.cast-item:last-child {
border-bottom: none;
}
.info {
margin-top: 20px;
text-align: center;
color: #666;
}
Loading…
Cancel
Save