# Quart **Repository Path**: chenbool/quart ## Basic Information - **Project Name**: Quart - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-12-31 - **Last Updated**: 2026-04-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Quart Web 应用框架 基于 [Quart](https://quart.palletsprojects.com/) 异步 Web 框架构建的轻量级 Web 应用。 ## 技术栈 | 类别 | 技术 | |------|------| | Web 框架 | Quart (异步 Flask) | | 数据库 | MySQL / SQLite | | ORM | Tortoise ORM | | 认证 | Quart-Auth (JWT) | | 模板 | Jinja2 | | CORS | quart-cors | ## 项目结构 ``` quart/ ├── app/ # 应用主目录 │ ├── controller/ # 控制器层 │ │ ├── admin/ # 后台管理模块 │ │ ├── api/ # API 接口模块 │ │ └── index/ # 前台首页模块 │ ├── model/ # 数据模型层 │ │ └── moji.py # 城市数据模型 │ ├── view/ # 模板视图 │ │ ├── admin/ │ │ └── index/ │ ├── __init__.py # 应用工厂 │ └── config.py # 配置文件 ├── util/ # 工具模块 │ ├── db.py # 数据库操作类 │ └── __init__.py # 工具函数 ├── main.py # 应用入口 ├── config.yaml # 配置文件 └── requirements.txt # 依赖列表 ``` ## 功能特性 - **多模块路由** - 支持前台、API、管理后台分离 - **数据库支持** - MySQL / SQLite 多种数据库 - **用户认证** - 基于 JWT 的用户认证系统 - **模板引擎** - 支持 Jinja2 模板渲染 - **CORS 支持** - 跨域资源共享配置 ## 快速开始 ### 1. 环境准备 ```bash # 创建虚拟环境 python -m venv venv # 激活虚拟环境 venv\Scripts\activate ``` ### 2. 安装依赖 ```bash # 安装项目依赖 pip install -r requirements.txt ``` ### 3. 配置数据库 编辑 `config.yaml` 文件: ```yaml database: type: sqlite # 或 mysql url: sqlite:///data.db host: 127.0.0.1 port: 3306 user: root pass: root db: test chartset: utf8mb4 redis: host: 127.0.0.1 port: 6379 debug: True port: 5000 jwt_secret: 'your-secret-key' ``` ### 4. 启动应用 ```bash python main.py ``` 访问 `http://127.0.0.1:5000` 即可。 ## 路由说明 | 模块 | 前缀 | 说明 | |------|------|------| | index | `/` | 前台首页 | | api | `/api` | API 接口 | | admin | `/admin` | 后台管理 | ## API 示例 ```python # 查询用户数据 from util.db import db # 查询单条 user = db('user').where({'id': 1}).find() # 查询多条 users = db('user').where({'status': 'active'}).all() # 分页查询 users = db('user').page(1, 10) ``` ## 开发指南 ### 创建新模块 ```python # app/controller/module_name/index.py from util import route, jsonify bp = route(__name__) @bp.get("/") async def home(): return jsonify({'msg': 'ok'}) ``` ### 添加需要登录的路由 ```python from quart_auth import login_required @bp.get("/protected") @login_required async def protected(): return jsonify({'msg': 'protected content'}) ``` ## 相关文档 - [Quart 官方文档](https://quart.palletsprojects.com/) - [Tortoise ORM 文档](https://tortoise-orm.readthedocs.io/) - [Records 数据库库](https://github.com/kennethreitz/records)