diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..e2e02cff1c84e156394ff0f81928633b259b6bef --- /dev/null +++ b/README.en.md @@ -0,0 +1,90 @@ +This project is a Python-based web application primarily designed to perform CRUD (Create, Read, Update, Delete) operations on student information. It utilizes modern web frameworks and a technology stack that supports asynchronous operations, providing both RESTful API interfaces and frontend page displays. + +--- + +## 📌 Feature Overview + +- **Student Management**: Supports adding, querying, updating, and deleting student information. +- **Data Validation**: Validates formats for fields such as student name and student ID. +- **Database Models**: Includes data models for students, courses, teachers, and classes. +- **Frontend Interface**: Provides HTML templates for displaying student data and statistics. +- **API Interface**: Offers RESTful API accessible via `/api/student`. +- **Database Migration**: Manages database schema changes using migration scripts. + +--- + +## 🧱 Technology Stack + +- **Backend Framework**: FastAPI (for building asynchronous APIs) +- **Database**: Tortoise ORM (asynchronous ORM) +- **Frontend Template**: Jinja2 (HTML rendering) +- **Deployment**: Docker (build image via `Dockerfile`) +- **Dependency Management**: `requirements.txt` and `pyproject.toml` + +--- + +## 📁 Project Structure Overview + +- `app.py`: Main program entry point, defines global routes and startup events. +- `api/student.py`: API route definitions related to students. +- `db/models.py`: Database model definitions (students, courses, teachers, classes). +- `templates/index.html`: Frontend page template for displaying student data and statistics. +- `migrations/`: Directory containing database migration scripts. +- `Dockerfile`: Used for building Docker images. + +--- + +## 🚀 Quick Start + +### 1. Install Dependencies + +```bash +pip install -r requirements.txt +``` + +### 2. Start the Service + +```bash +uvicorn app:app --host 0.0.0.0 --port 8005 +``` + +### 3. Build and Run Using Docker + +```bash +docker build -t student_crud . +docker run -p 8005:8005 student_crud +``` + +--- + +## 🌐 API Interface Description + +- `GET /api/student`: Retrieve a list of students (supports pagination) +- `GET /api/student/{student_id}`: Retrieve details of a student by ID +- `POST /api/student`: Add a new student +- `PUT /api/student/{student_id}`: Update student information +- `DELETE /api/student/{student_id}`: Delete a student +- `GET /api/student/search`: Search students by keyword + +--- + +## 📊 Frontend Page Features + +- Displays statistics such as total number of students, gender ratio, and average age +- Supports searching and paginating through student data +- Provides modal dialogs for adding or editing student information + +--- + +## 📜 Database Migration + +Use the scripts in the `migrations/` directory to manage database schema changes: + +- `upgrade()`: Upgrade the database schema +- `downgrade()`: Roll back the database schema + +--- + +## 📝 License + +This project is licensed under the MIT License. Please refer to the `LICENSE` file in the project root directory for more details. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000000000000000000000000000000000000..97b7fab3c4582d90903f135c69645e817ff11142 --- /dev/null +++ b/README.md @@ -0,0 +1,90 @@ +该项目是一个基于Python的Web应用程序,主要用于学生信息的增删改查(CRUD)操作。它使用了现代Web框架和技术栈,支持异步操作,并提供了RESTful API接口以及前端页面展示。 + +--- + +## 📌 功能概述 + +- **学生管理**:支持添加、查询、更新和删除学生信息。 +- **数据验证**:对学生姓名和学号等字段进行格式校验。 +- **数据库模型**:包含学生、课程、教师和班级等数据模型。 +- **前端界面**:提供HTML模板用于展示学生数据和统计信息。 +- **API接口**:通过 `/api/student` 提供RESTful API供外部调用。 +- **数据库迁移**:使用迁移脚本管理数据库结构变更。 + +--- + +## 🧱 技术栈 + +- **后端框架**:FastAPI(用于构建异步API) +- **数据库**:Tortoise ORM(异步ORM) +- **前端模板**:Jinja2(HTML渲染) +- **部署方式**:Docker(通过 `Dockerfile` 构建镜像) +- **依赖管理**:`requirements.txt` 和 `pyproject.toml` + +--- + +## 📁 项目结构简述 + +- `app.py`:主程序入口,定义全局路由和启动事件。 +- `api/student.py`:学生相关的API路由定义。 +- `db/models.py`:数据库模型定义(学生、课程、教师、班级)。 +- `templates/index.html`:前端页面模板,展示学生数据和统计信息。 +- `migrations/`:数据库迁移脚本。 +- `Dockerfile`:用于构建Docker镜像。 + +--- + +## 🚀 快速开始 + +### 1. 安装依赖 + +```bash +pip install -r requirements.txt +``` + +### 2. 启动服务 + +```bash +uvicorn app:app --host 0.0.0.0 --port 8005 +``` + +### 3. 使用 Docker 构建并运行 + +```bash +docker build -t student_crud . +docker run -p 8005:8005 student_crud +``` + +--- + +## 🌐 API 接口说明 + +- `GET /api/student`:获取学生列表(支持分页) +- `GET /api/student/{student_id}`:根据ID获取学生详情 +- `POST /api/student`:添加新学生 +- `PUT /api/student/{student_id}`:更新学生信息 +- `DELETE /api/student/{student_id}`:删除学生 +- `GET /api/student/search`:根据关键字搜索学生 + +--- + +## 📊 前端页面功能 + +- 展示学生总数、男女比例、平均年龄等统计信息 +- 支持搜索、分页浏览学生数据 +- 提供模态框用于新增或编辑学生信息 + +--- + +## 📜 数据库迁移 + +使用 `migrations/` 目录下的脚本进行数据库结构管理: + +- `upgrade()`:升级数据库结构 +- `downgrade()`:回滚数据库结构 + +--- + +## 📝 许可证 + +本项目遵循 MIT 许可证,请参阅项目根目录下的 `LICENSE` 文件获取详细信息。 \ No newline at end of file