问题描述
我有一个具有以下结构的Django项目:root
视频
static
模板
和我设法使用pyinstaller从manage.py创建一个Windows可执行文件,这是STA.py_URL中的settings.py中的STATIC_URL设置为STATIC_URL ='/ static /'
我可以启动Django服务器,但我无法确定静态文件的位置。
当我第一次启动服务器时,它也找不到模板,它在以下位置搜索它们:'root\django\contrib\admin\templates\videos\''我将模板复制到这个文件夹,它的工作。但是我无法弄清静态文件的位置。我尝试将它们放在root\django\contrib\admin\static中以重新创建原始结构。但是似乎它不在那里搜索...
任何人都知道静态文件应该去哪里?或者如何定义捆绑的pyinstaller exe将寻找他们的地方?
请参阅您的urls.py文件中
,您应该添加类似于
从django.conf导入设置
from django.conf.urls.static import static
urlpatterns = [
url(r'^ login $', login = name ='login'),
] + static(settings.STATIC_URL,document_root = settings.STATIC_ROOT)
并在你的app.spec文件中添加数据
datas = [('xxx / templates' 'xxx / templates'),
('xxx / static','xxx / static')],
I have a Django project with the following structure:root videos static templates
and the STATIC_URL setting in settings.py is STATIC_URL = '/static/'
I managed to use pyinstaller to create a windows executable from manage.py. I can start the Django server but I can't figure out where to put the static files.
When I first started the server it could not find the templates as well, it searched for them in : 'root\django\contrib\admin\templates\videos\' I copied the templates to this folder and it worked. But I can't figure out where to put the static files. I tried putting them in 'root\django\contrib\admin\static' to recreate the original structure. But it seems it doesn't search for them there...
Anyone knows where the static files should go? Or how to define the place where a bundled pyinstaller exe will look for them ?
please see https://docs.djangoproject.com/en/1.10/howto/static-files/
in your urls.py file, you should add something like blew
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^login$', login, name='login'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
and in your app.spec file, add datas
datas=[('xxx/templates','xxx/templates'),
('xxx/static','xxx/static')],
这篇关于使用pyinstaller创建Django exe时静态文件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!