python - runsslserver 命令无法在 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.
设置.py
INSTALLED_APPS = (...
"sslserver",
...
)
当我使用pyinstaller构建可执行文件时(我已经在文件中包含了包,.spec
例如,Analysis(hiddenimports=[...,'sslserver',...])
并与命令一起使用,XApp.exe runsslserver 8000
那么它会显示如下消息,
Unknown command: 'runsslserver'
Type 'manage.py help' for usage.
我该如何解决?
解决方案
我通过在命令字典中添加'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
推荐阅读
- php - PHP foreach 循环不更新值
- python - 使用代理和 Selenium 时 URL 发生变化
- sql - 在 Oracle 中按日期设置行顺序时遇到问题
- java - Spring WebFlux + Security - 我们有“记住我”功能吗?
- c# - Web API HttpPost 方法总是接收 GET
- css - 响应式 YouTube 嵌入式视频设置为特定尺寸,没有黑色边框
- swift - 等待 MessageKit 函数中的另一个函数完成
- django - Django:模型中只有 1 个字段未更新
- java - 可运行的 javafx 应用程序中的 Unirest
- javascript - 从另一个代码库运行 tensorflow