diff --git a/.env b/.env index 0c4c5c3..6118cfa 100644 --- a/.env +++ b/.env @@ -27,12 +27,13 @@ EMAIL_HOST=smtp.qq.com EMAIL_PORT=465 EMAIL_USE_SSL=True EMAIL_USE_TLS=False -EMAIL_HOST_USER= -EMAIL_HOST_PASSWORD= -DEFAULT_FROM_EMAIL= +EMAIL_HOST_USER=your_email@example.com +EMAIL_HOST_PASSWORD=your_email_password_or_app_key +DEFAULT_FROM_EMAIL=your_email@example.com # 注册邮箱验证码开关(0=关闭,1=开启) REGISTER_EMAIL_VERIFICATION=0 + # Hertz Captcha Configuration HERTZ_CAPTCHA_LENGTH=4 HERTZ_CAPTCHA_WIDTH=120 diff --git a/.gitignore b/.gitignore index f0aa2fe..9c52905 100644 --- a/.gitignore +++ b/.gitignore @@ -95,4 +95,4 @@ Thumbs.db hertz_studio_django_utils/yolo/Train/runs/ # 技术支持文档 -shared/ \ No newline at end of file +shared/ diff --git a/data/db.sqlite3 b/data/db.sqlite3 index 98e7ccc..045100f 100644 Binary files a/data/db.sqlite3 and b/data/db.sqlite3 differ diff --git a/docs/img/ac87c1f6-a28b-4959-ae98-cab5e150c56b.png b/docs/img/ac87c1f6-a28b-4959-ae98-cab5e150c56b.png new file mode 100644 index 0000000..d3927ef Binary files /dev/null and b/docs/img/ac87c1f6-a28b-4959-ae98-cab5e150c56b.png differ diff --git a/docs/img/img_1.png b/docs/img/img_1.png new file mode 100644 index 0000000..4066932 Binary files /dev/null and b/docs/img/img_1.png differ diff --git a/docs/img/img_2.png b/docs/img/img_2.png new file mode 100644 index 0000000..626c471 Binary files /dev/null and b/docs/img/img_2.png differ diff --git a/docs/img/img_3.png b/docs/img/img_3.png new file mode 100644 index 0000000..d3d0a40 Binary files /dev/null and b/docs/img/img_3.png differ diff --git a/get_machine_code.py b/get_machine_code.py new file mode 100644 index 0000000..b4b2d42 --- /dev/null +++ b/get_machine_code.py @@ -0,0 +1,18 @@ +import platform +import uuid +import hashlib + + +def get_machine_id() -> str: + """生成机器码。 + + 根据当前系统信息(平台、架构、MAC地址)生成唯一机器码, + 使用 SHA256 取前16位并转大写,前缀为 HERTZ_STUDIO_。 + """ + system_info = f"{platform.platform()}-{platform.machine()}-{uuid.getnode()}" + return 'HERTZ_STUDIO_' + hashlib.sha256(system_info.encode()).hexdigest()[:16].upper() + + +if __name__ == "__main__": + machine_code = get_machine_id() + print(f"您的机器码是: {machine_code}") \ No newline at end of file diff --git a/hertz_server_django/settings.py b/hertz_server_django/settings.py index 6b04272..ed2e644 100644 --- a/hertz_server_django/settings.py +++ b/hertz_server_django/settings.py @@ -81,17 +81,14 @@ INSTALLED_APPS = [ 'channels', 'drf_spectacular', - # Local apps - 'hertz_demo', - 'hertz_studio_django_captcha', - 'hertz_studio_django_auth', # 权限管理系统 - 'hertz_studio_django_notice', # 通知公告模块 - 'hertz_studio_django_ai', + # 必备注册的app,不要删 + 'hertz_demo', # 初始化演示模块 + 'hertz_studio_django_captcha', # 验证码模块 + 'hertz_studio_django_auth', # 权限模块 'hertz_studio_django_system_monitor', # 系统监测模块 'hertz_studio_django_log', # 日志管理模块 - 'hertz_studio_django_wiki', # 知识管理模块 - 'hertz_studio_django_codegen', # 代码生成模块 - 'hertz_studio_django_yolo', # YOLO目标检测模块 + + # ======在下面导入你需要的app====== ] diff --git a/hertz_server_django/urls.py b/hertz_server_django/urls.py index 003a589..b7f3588 100644 --- a/hertz_server_django/urls.py +++ b/hertz_server_django/urls.py @@ -19,53 +19,35 @@ from django.conf import settings from django.conf.urls.static import static from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView from . import views -from hertz_studio_django_captcha import urls as captcha_urls -import sys -from pathlib import Path -_BASE_DIR = Path(__file__).resolve().parent.parent -sys.path.insert(0, str(_BASE_DIR)) -from hertz_studio_django_codegen import urls as codegen_urls urlpatterns = [ + + # API documentation routes + path('api/docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), + path('api/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'), + path('api/schema/', SpectacularAPIView.as_view(), name='schema'), + # 首页路由 path('', views.index, name='index'), # Hertz Captcha routes - path('api/captcha/', include(captcha_urls)), + path('api/captcha/', include('hertz_studio_django_captcha.urls')), # Hertz Auth routes path('api/', include('hertz_studio_django_auth.urls')), # Demo app routes path('', include('hertz_demo.urls')), - - # Hertz AI routes - path('api/ai/', include('hertz_studio_django_ai.urls')), - + # Hertz System Monitor routes path('api/system/', include('hertz_studio_django_system_monitor.urls')), - - # Hertz System Notification routes - path('api/notice/', include('hertz_studio_django_notice.urls')), - + # Hertz Log routes path('api/log/', include('hertz_studio_django_log.urls')), - - ## Hertz Wiki routes - path('api/wiki/', include('hertz_studio_django_wiki.urls')), - - # Hertz Codegen routes - path('api/codegen/', include((codegen_urls, 'codegen'), namespace='codegen')), - - # Hertz YOLO routes - path('api/yolo/', include('hertz_studio_django_yolo.urls')), - - - # API documentation routes - path('api/docs/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), - path('api/redoc/', SpectacularRedocView.as_view(url_name='schema'), name='redoc'), - path('api/schema/', SpectacularAPIView.as_view(), name='schema'), + + # ===========在下面添加你需要的路由=========== + ] # 在开发环境下提供媒体文件服务 diff --git a/requirements.txt b/requirements.txt index f9257c5..4bd0b1a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -Django==5.2.6 +Django==5.1.2 channels==4.0.0 channels-redis==4.2.0 djangorestframework==3.14.0 @@ -22,12 +22,16 @@ scikit-learn>=1.1.0 joblib>=1.2.0 aiohttp>=3.13.2 -hertz-studio-django-ai>=0.1.0 -hertz-studio-django-auth>=0.1.0 -hertz-studio-django-captcha>=0.1.0 -hertz-studio-django-log>=0.1.0 -hertz-studio-django-notice>=0.1.0 -hertz-studio-django-system-monitor>=0.1.0 -hertz-studio-django-wiki>=0.1.0 -hertz-studio-django-yolo>=0.1.0 -hertz-studio-django-codegen>=0.1.0 \ No newline at end of file + + +# ================hertz所有官方库================ +hertz-studio-django-ai +hertz-studio-django-auth +hertz-studio-django-captcha +hertz-studio-django-log +hertz-studio-django-notice +hertz-studio-django-system-monitor +hertz-studio-django-wiki +hertz-studio-django-yolo +hertz-studio-django-codegen +hertz-studio-django-yolo-train \ No newline at end of file diff --git a/后端部署教程.md b/后端部署教程.md new file mode 100644 index 0000000..857e3d8 --- /dev/null +++ b/后端部署教程.md @@ -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/ + +![机器码激活](docs/img/ac87c1f6-a28b-4959-ae98-cab5e150c56b.png) + +## 三、下载需要的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等模块 +![app注册](docs/img/img_1.png) + +### 2)注册app后配置路由 + +在根目录下面的hertz_server_django文件夹下面的urls.py文件(如下图)中配置路由 + +配置路由参考,例如我要配置名为xxx的路由: + +```python +path('api/xxx/', include('hertz_studio_django_xxx.urls')), +``` + +如下图我配置了notice、ai、wiki等路由 +![路由配置](docs/img/img_2.png) + + + + + + +## **五、启动服务** + +- 通过脚本启动(支持端口参数): + - `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目录下,如下图。 + ![ffmpeg配置](docs/img/img_3.png) + + + + +## **八、项目结构** + +- 核心配置:`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`