更新
This commit is contained in:
133
后端部署教程.md
Normal file
133
后端部署教程.md
Normal file
@@ -0,0 +1,133 @@
|
||||
# 后端部署教程
|
||||
|
||||
|
||||
|
||||
## 一、**环境要求**
|
||||
|
||||
- `Python 3.10+`(建议 3.12.3)
|
||||
- 操作系统:Windows
|
||||
- 可选:本地 `Redis` 服务(默认地址 `redis://127.0.0.1:6379`)
|
||||
|
||||
|
||||
|
||||
## 二、 获取机器码并激活
|
||||
|
||||
### 1)获取机器码:
|
||||
|
||||
```python
|
||||
python get_machine_code.py
|
||||
```
|
||||
|
||||
允许后会获得一个机器码,例如:HERTZ_STUDIO_XXXXXXXXXXXXXXXX
|
||||
|
||||
### 2)将获取到的机器码在激活码管理系统上添加
|
||||
|
||||
进行系统地址(没有账号请找管理员申请):http://activate.hzsystems.cn/admin/machinecode/
|
||||
|
||||

|
||||
|
||||
## 三、下载需要的app库
|
||||
|
||||
### 1)单独获取库,例如需要yolo模块库:
|
||||
|
||||
```bash
|
||||
pip install hertz-studio-django-yolo -i https://hertz:hertz@hzpypi.hzsystems.cn/simple/
|
||||
```
|
||||
|
||||
### 2)下载全部库
|
||||
|
||||
pip install -r requirements.txt -i https://hzpypi.hzsystems.cn/simple/
|
||||
|
||||
|
||||
|
||||
注:所有库都在requirements.txt的最下面
|
||||
|
||||
|
||||
|
||||
## 四、配置django
|
||||
|
||||
### 1)将下载的app注册到django项目中
|
||||
|
||||
在根目录下面的hertz_server_django文件夹下面的setting文件(如下图)中注册app
|
||||
|
||||
如下图我用到了notice、ai、wiki等模块
|
||||

|
||||
|
||||
### 2)注册app后配置路由
|
||||
|
||||
在根目录下面的hertz_server_django文件夹下面的urls.py文件(如下图)中配置路由
|
||||
|
||||
配置路由参考,例如我要配置名为xxx的路由:
|
||||
|
||||
```python
|
||||
path('api/xxx/', include('hertz_studio_django_xxx.urls')),
|
||||
```
|
||||
|
||||
如下图我配置了notice、ai、wiki等路由
|
||||

|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## **五、启动服务**
|
||||
|
||||
- 通过脚本启动(支持端口参数):
|
||||
- `python start_server.py --port 8000`
|
||||
- 访问地址:
|
||||
- `http://127.0.0.1:8000/`
|
||||
- WebSocket:`ws://127.0.0.1:8000/ws/`
|
||||
- 首次启动将自动执行:
|
||||
- 扫描并注册新应用到 `INSTALLED_APPS` 与 `urls.py`(`start_server.py:173`、`start_server.py:98`)。
|
||||
- 执行 `makemigrations` 与 `migrate`(`start_server.py:1109`)。
|
||||
- 初始化超级管理员/部门/菜单/角色等(`start_server.py:877`)。
|
||||
- 创建菜单生成器工具 `generate_menu.py`(`start_server.py:780`)。
|
||||
- 启动 `daphne` 并开启热重启监听(`start_server.py:1016`、`start_server.py:1063`)。
|
||||
|
||||
|
||||
|
||||
## 六、默认账号
|
||||
|
||||
- 超级管理员:
|
||||
- 用户名:`hertz`
|
||||
- 密码:`hertz`
|
||||
- 普通用户
|
||||
- 用户名:`demo`
|
||||
- 密码:`123456`
|
||||
|
||||
|
||||
|
||||
## **七、问题排查**
|
||||
|
||||
### 1)`daphne` 或 `watchdog` 未安装:
|
||||
|
||||
运行:`pip install daphne watchdog -i https://pypi.tuna.tsinghua.edu.cn/simple`(`start_server.py:1235-1248` 有依赖检查)。
|
||||
|
||||
### 2)Redis 未运行:
|
||||
|
||||
安装并启动 Redis,或调整 `REDIS_URL` 指向可用实例。
|
||||
|
||||
### 3)视频检测结果展示不了
|
||||
|
||||
需配置ffmpeg环境,参考文章:https://blog.csdn.net/csdn_yudong/article/details/129182648
|
||||
|
||||
ffmpeg压缩包在根目录下面的static目录下,如下图。
|
||||

|
||||
|
||||
|
||||
|
||||
|
||||
## **八、项目结构**
|
||||
|
||||
- 核心配置:`hertz_server_django/settings.py`、`hertz_server_django/urls.py`
|
||||
- 启动脚本:`start_server.py`
|
||||
- 依赖清单:`requirements.txt`
|
||||
- 静态资源:`static/`,媒体资源:`media/`
|
||||
|
||||
|
||||
|
||||
## 九、**快速启动**
|
||||
|
||||
- 安装依赖:`pip install -r requirements.txt -i https://hertz:hertz@hzpypi.hzsystems.cn/simple/`
|
||||
- 启动服务:`python start_server.py --port 8000`
|
||||
Reference in New Issue
Block a user