Gogs 9 місяців тому
батько
коміт
07628ec2f9
4 змінених файлів з 33 додано та 4 видалено
  1. 3 3
      app.py
  2. 1 1
      file_uploader.py
  3. BIN
      static/123.jpg
  4. 29 0
      templates/index.html

+ 3 - 3
app.py

@@ -1,5 +1,5 @@
 # -*- coding: utf-8 -*-
-from flask import Flask, jsonify, request
+from flask import Flask, jsonify, request, render_template
 from db_utils.data import *
 from db_utils.files import *
 from file_uploader import upload_file  # 导入文件上传的函数
@@ -17,7 +17,7 @@ initialize_files_table()
 
 @app.route('/')
 def home():
-    return "Welcome to the Fruit API!"
+    return render_template('index.html')
 
 # 添加水果数据
 @app.route('/add_fruit', methods=['POST'])
@@ -69,7 +69,7 @@ def upload():
 @app.route('/download/<filename>', methods=['GET'])
 def download_file(filename):
     from flask import send_from_directory
-    return send_from_directory('uploads', filename)
+    return send_from_directory('../uploads', filename)
 
 # 运行 Flask 应用
 if __name__ == '__main__':

+ 1 - 1
file_uploader.py

@@ -10,7 +10,7 @@ if not os.path.exists(UPLOAD_FOLDER):
     os.makedirs(UPLOAD_FOLDER)
 
 # 允许的文件扩展名
-ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'pdf','mp4'}
+ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'pdf','mp4','apk'}
 
 
 def allowed_file(filename):

BIN
static/123.jpg


+ 29 - 0
templates/index.html

@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>图片展示</title>
+    <style>
+        body {
+            display: flex;
+            justify-content: center;
+            align-items: center;
+            height: 100vh;
+            margin: 0;
+            background-color: #f0f0f0;
+        }
+        img {
+            max-width: 100%;
+            max-height: 100%;
+            border: 2px solid #ccc;
+            border-radius: 8px;
+            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
+        }
+    </style>
+</head>
+<body>
+    <!-- 图片路径可替换为实际文件路径 -->
+    <img src="/static/123.jpg" alt="展示图片">
+</body>
+</html>