Pyinstaller不';t包括django rest框架模板
我有一个django应用程序,它使用rest_框架,一切都很好,我正在使用pyinstaller为这个应用程序获取一个exe,这个可执行的应用程序工作得很好,但是当我尝试访问rest框架的可浏览api时,比如http://localhost:8000/api/flags/ 为了查看可浏览的api,我得到了以下错误Pyinstaller不';t包括django rest框架模板,django,django-rest-framework,pyinstaller,Django,Django Rest Framework,Pyinstaller,我有一个django应用程序,它使用rest_框架,一切都很好,我正在使用pyinstaller为这个应用程序获取一个exe,这个可执行的应用程序工作得很好,但是当我尝试访问rest框架的可浏览api时,比如http://localhost:8000/api/flags/ 为了查看可浏览的api,我得到了以下错误 TemplateDoesNotExist at /api/flags/ rest_framework/horizontal/form.html Request Method: GET
TemplateDoesNotExist at /api/flags/
rest_framework/horizontal/form.html
Request Method: GET
Request URL: http://localhost:8000/api/flags/
Django Version: 3.0.7
Exception Type: TemplateDoesNotExist
Exception Value:
rest_framework/horizontal/form.html
Exception Location: site-packages\django\template\loader.py in get_template, line 19
Python Executable: C:\Workset\proj_test\app.exe
Python Version: 3.8.3
Python Path:
['C:\\Workset\\proj_test\\dist\\app\\base_library.zip',
'C:\\Workset\\proj_test\\dist\\app']
Server time: Thu, 9 Jul 2020 09:52:53 +0000
Template-loader postmortem
Django tried loading these templates, in this order:
Using engine django:
django.template.loaders.filesystem.Loader: C:\Workset\proj_test\dist\app\src\templates\rest_framework\horizontal\form.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Workset\proj_test\dist\app\django\contrib\admin\templates\rest_framework\horizontal\form.html (Source does not exist)
django.template.loaders.app_directories.Loader: C:\Workset\proj_test\dist\app\django\contrib\auth\templates\rest_framework\horizontal\form.html (Source does not exist)
这意味着Pyinstaller不包括rest_框架默认ui模板,我如何在Pyinstaller生成的output dist文件夹中包括这些模板
注意:restapi本身工作正常,即调用restapi工作正常我知道这是一篇比较老的文章,但我想我会分享我的解决方案 我在这里找到了django特定的hook文件(linux机器):/home/>/.local/lib/python3.6/site-packages/PyInstaller/hooks/hook-django.py 发现它只提取了django site packages文件夹中的任何内容。Django rest_框架不包括在Django站点包中,它位于同一级别上它自己的文件夹中。因此,通过添加以下代码,我编辑了这个钩子文件以包括rest_framework文件夹:
datas, binaries, hiddenimports = collect_all('django')
datas_rest, binaries_rest, hiddenimports_rest = collect_all('rest_framework')
datas += datas_rest
binaries += binaries_rest
hiddenimports += hiddenimports_rest
然后重新运行pyinstaller。确保在dist文件夹中包含rest\u framework文件夹。我知道这是一篇比较老的文章,但我想我会分享我的解决方案 我在这里找到了django特定的hook文件(linux机器):/home/>/.local/lib/python3.6/site-packages/PyInstaller/hooks/hook-django.py 发现它只提取了django site packages文件夹中的任何内容。Django rest_框架不包括在Django站点包中,它位于同一级别上它自己的文件夹中。因此,通过添加以下代码,我编辑了这个钩子文件以包括rest_framework文件夹:
datas, binaries, hiddenimports = collect_all('django')
datas_rest, binaries_rest, hiddenimports_rest = collect_all('rest_framework')
datas += datas_rest
binaries += binaries_rest
hiddenimports += hiddenimports_rest
然后重新运行pyinstaller。确保它在dist文件夹中包含rest\u framework文件夹。感谢您指出API的其余部分工作正常;我一直在努力解决这个问题,并假设整个API都被破坏了;我一直在努力解决这个问题,并假设整个API都被破坏了。