python - runningslserver 命令在 django 中无法使用 pyinstaller 构建的可执行文件运行

标签 python django pyinstaller

我正在使用runsslserver运行 django 应用程序的命令。在生成可执行文件之前在命令行上运行并且工作正常例如,

Validating models...

System check identified no issues (0 silenced).
June 11, 2018 - 16:57:54
Django version 2.0.4, using settings 'XApp.settings'
Starting development server at https://0:8002/
Quit the server with CTRL-BREAK.

Settings.py

INSTALLED_APPS = (...
"sslserver",
...
)

当我使用 pyinstaller 构建可执行文件时(我已经将包包含在 .spec 文件中,例如 Analysis(hiddenimports=[...,'sslserver',...]) 并与命令 一起使用XApp.exe 运行 slserver 8000 然后显示类似消息,

Unknown command: 'runsslserver'
Type 'manage.py help' for usage.

如何解决?

最佳答案

我通过在 commands 字典中添加 'runsslserver':'sslserver' 找到了解决方案

PyInstaller\loader\rthooks\pyi_rth_django.py 文件。

import django.core.management
import django.utils.autoreload


def _get_commands():
    # Django groupss commands by app.
    # This returns static dict() as it is for django 1.8 and the default project.
    commands = {
         'changepassword': 'django.contrib.auth',
         'check': 'django.core',
         'clearsessions': 'django.contrib.sessions',
         'collectstatic': 'django.contrib.staticfiles',
         'compilemessages': 'django.core',
         'createcachetable': 'django.core',
         'createsuperuser': 'django.contrib.auth',
         'dbshell': 'django.core',
         'diffsettings': 'django.core',
         'dumpdata': 'django.core',
         'findstatic': 'django.contrib.staticfiles',
         'flush': 'django.core',
         'inspectdb': 'django.core',
         'loaddata': 'django.core',
         'makemessages': 'django.core',
         'makemigrations': 'django.core',
         'migrate': 'django.core',
         'runfcgi': 'django.core',
         'runserver': 'django.core',
         'runsslserver':'sslserver',
         'shell': 'django.core',
         'showmigrations': 'django.core',
         'sql': 'django.core',
         'sqlall': 'django.core',
         'sqlclear': 'django.core',
         'sqlcustom': 'django.core',
         'sqldropindexes': 'django.core',
         'sqlflush': 'django.core',
         'sqlindexes': 'django.core',
         'sqlmigrate': 'django.core',
         'sqlsequencereset': 'django.core',
         'squashmigrations': 'django.core',
         'startapp': 'django.core',
         'startproject': 'django.core',
         'syncdb': 'django.core',
         'test': 'django.core',
         'testserver': 'django.core',
         'validate': 'django.core'
    }
    return commands

关于python - runningslserver 命令在 django 中无法使用 pyinstaller 构建的可执行文件运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50808934/

相关文章:

python - 运行 PyInstaller 生成的二进制文件时出现模块导入错误

python - 如何抑制pyinstaller生成的可执行文件窗口中的所有警告

python - 根据每个嵌套列表的总和对列表列表进行排序

python - 优化mysql多次更新

python - 值错误 : Data must be positive (boxcox scipy)

Django 身份验证失败搜索注册/login.html

django - React请求Django API时,出现net::ERR_SSL_PROTOCOL_ERROR

python - 在 kivy 中有建议的搜索框?

模板中的Django注释值

python - Tkinter 可以部分点击吗? (仅限 Windows)