fastapi-template/README.md

88 lines
3.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# FastAPI App 文档
## 0 开发说明
Python(3.10+) and pip(20.2.4+)
### 开发命名规范
> * 避免采用的名字
> 不要使用字符l小写字母elO大写字母ohI大写字母eye作为单字符变量名。
> * 包名和模块名
> 模块名应该短所有的字母小写。可以在模块名中使用下划线来提高可读性。Python包名也应该短所有的字母小写不鼓励使用下划线。
> * 类名
> 类名通常使用首字母大写字符串的规则。
> * 函数名
> 函数名应该是小写字母,必要时单词用下划线分开以提高可读性。
> * 函数和方法参数
> 使用self做实例化方法的第一个参数使用cls做类方法的第一个参数。如果函数的参数名与保留关键字冲突最好是为参数名添加一个后置下划线而不是使用缩写或拼写错误。因此class_ 比clss好。也许使用同义词来避免更好
## 1 配置conf文件
> (没有的话需要自己创建,放在conf文件夹下级)
``` bash
===================== conf-dev.ini =========================
[common]
static_folder=./static
template_folder=./templates
[mysql]
username=admin
password=123456
host=localhost
port=3306
database=test
```
## 2 开发环境下安装依赖和运行项目
``` bash
pip install poetry -i https://pypi.tuna.tsinghua.edu.cn/simple/ \
&& poetry source add --priority=primary mirrors https://pypi.tuna.tsinghua.edu.cn/simple/ \
&& poetry config virtualenvs.path /install \
&& poetry install
./start.bat (windows)
./start.sh (mac/linux)
```
## 3 models文件夹下的SQLAlchemy Model代码生成
```bash
安装完依赖库后,即可通过命令行工具直接生成,无须手写。 例子参考如下:
sqlacodegen.exe --tables permission_info --outfile .\Desktop\fastapi_app\models\permission_info.py mysql+pymysql://chenwj:123456@localhost/waterv3?charset=utf8
```
## 4 各个目录和文件备注
```
conf *配置文件目录
|--- conf-dev.ini *开发环境配置文件
|--- conf-prod.ini *生产环境配置文件
|--- log.ini *日志配置文件
files *上传文件目录
logs *日志文件目录
src *源码目录
|--- api *接口目录
|--- service *逻辑目录
|--- dtos *接口参数和返回值目录
|--- models *数据model目录
|--- middleware *中间件目录
|--- router *路由目录 ----- TODO
|--- utils *工具类目录
|--- captcha *验证码
|--- common *常规
|--- exception *异常处理
|--- file_upload *文件上传
|--- qiniu_tools *七牛
|--- sms *短信
static *静态文件目录
test *测试目录
.gitignore *git忽略文件
.gitlab-ci.yml * CI/CD文件
main.py *入口文件
config.py *配置入口文件
Dockerfile *dockerfile容器代码
RuntimeDockerfile *dockerfile容器运行环境
requirements.txt * pip依赖包安装文件
pyproject.toml * poetry依赖包安装文件
poetry.lock * poetry依赖包安装文件
Pipfile * pipenv安装文件
Pipfile.lock * pipenv安装文件
README.md * 项目说明文件
start.bat *Windows开发环境下启动文件
start.sh *Unix开发环境下启动文件