Files
app_package/使用手册.md
2025-11-25 11:41:56 +08:00

2.8 KiB
Raw Permalink Blame History

APP打包教程

请先运行get_license.py脚本获取机器码 并将机器码交给机器码管理人员负责授权!!!

一、复制APP

将要打包的APP复制粘贴到根目录

二、编辑APP下面的apps.py文件

在apps.py文件中添加该函数

def ready(self):
    """Django 应用启动时的钩子。
    在此执行运行时授权校验,未授权则抛出异常阻止应用启动。
    """
    try:
        from .license_verifier import verify_machine_license
        verify_machine_license()
    except Exception:
        # 直接再抛出,让 Django 启动失败并展示错误信息
        raise

三、迁移license

  1. 将根目录下面的license_verifier.py复制粘贴到要打包的APP下

  2. 修改license_verifier.py文件

    将下面的PACKAGE_NAME的值改为要把包的app名称

    PACKAGE_NAME = "hertz_studio_django_xxxxx"
    

    修改该脚本最后一行代码将Xxxxx改为打包的app简称:

    raise RuntimeError("Hertz Xxxxx license verification failed")
    

四、修改MANIFEST.in文件

将下面的hertz_studio_django_xxx改为打包的app名称

#  包含二进制文件
recursive-include hertz_studio_django_xxx *.py
recursive-include hertz_studio_django_xxx/migrations *.py

五、修改根目录下面的setup.py文件

  • 修改成要打包的app名称将hertz_studio_django_xxx改为打包的app名称
package_name = 'hertz_studio_django_xxx'
  • 将XXX改为app简称
print("欢迎使用 Hertz System xxx!")
  • 更改下载的项目地址将hertz_studio_django_xxx改为打包的app名称
url="http://hzgit.hzsystems.cn/hertz_studio_django/hertz_studio_django_xxx",  # 项目地址
  • 更改关键词将XXX改为app简称
keywords="django XXXX verification security",  # 关键词
  • 修改project_urls将xxx改为app简称
project_urls={

  "Bug Reports": "http://hzgit.hzsystems.cn/hertz_studio_django/hertz_studio_django_xxx/issues",

  "Source": "http://hzgit.hzsystems.cn/hertz_studio_django/hertz_studio_django_xxx",

  "Documentation": "http://hzgit.hzsystems.cn/hertz_studio_django/hertz_studio_django_xxx#readme",

}

六、打包

完成上述的修改后,在终端的项目输入以下命令并回车进行打包

python setup.py sdist bdist_wheel

运行完成后会在dist目录下生成两个文件

hertz_studio_django_yolo-1.0.1.tar.gz和hertz_studio_django_yolo-1.0.1-py3-none-any.whl

七、测试pip下载

测试时请将下面的hertz_studio_django_yolo-1.0.1-py3-none-any.whl换成你自己生成的文件

pip install dist/hertz_studio_django_yolo-1.0.1-py3-none-any.whl

八、将生成的两个文件交给仓库源管理人员上传