2017-01-03 108 views
0

我創建djnago項目followong靜態文件是Pyinstaller不能找到

mysite 
--settings.py 
-- urls.py 
--wsgi.py 

polls(app) 
--static 
    --polls 
    --images 
--templates 
    --polls 
    index.html 
    results.html 
admin.py 
apps.py 
models.py 
urls.py 
views.py 

我一直在使用pyinstaller 是exe文件運行良好能夠加載模板 但對靜態文件(CSS創建安裝項目的目錄結構和JS),exe文件給我的錯誤

C:\Users\sanjad\Desktop\testdemo\myinstaller>dist\manage\manage.exe runserver 
Performing system checks... 

System check identified no issues (0 silenced). 
January 03, 2017 - 10:10:15 
Django version 1.10.2, using settings 'mysite.settings' 
Starting development server at http://127.0.0.1:8000/ 
Quit the server with CTRL-BREAK. 
[03/Jan/2017 10:10:18] "GET/HTTP/1.1" 200 346 
Not Found: /static/polls/style.css 
[03/Jan/2017 10:10:18] "GET /static/polls/style.css HTTP/1.1" 404 2605 

以下是我的.spec文件

# -*- mode: python -*- 

block_cipher = None 


a = Analysis(['..\\mysite\\manage.py'], 
      pathex=['C:\\Users\\sanjad\\Desktop\\testdemo\\myinstaller'], 
      binaries=None, 
      datas=[ 
        ('C:\\Users\\sanjad\\Desktop\\testdemo\\mysite\\polls\\templates\\','polls\\templates'), 
        ('C:\\Users\\sanjad\\Desktop\\testdemo\\mysite\\polls\\static\\','polls\\static') 
        ], 
      hiddenimports=[], 
      hookspath=[], 
      runtime_hooks=[], 
      excludes=[], 
      win_no_prefer_redirects=False, 
      win_private_assemblies=False, 
      cipher=block_cipher) 
pyz = PYZ(a.pure, a.zipped_data, 
      cipher=block_cipher) 
exe = EXE(pyz, 
      a.scripts, 
      exclude_binaries=True, 
      name='manage', 
      debug=False, 
      strip=False, 
      upx=True, 
      console=True) 
coll = COLLECT(exe, 
       a.binaries, 
       a.zipfiles, 
       a.datas, 
       strip=False, 
       upx=True, 
       name='manage') 
+0

你見過https://github.com/pyinstaller/pyinstaller/wiki/If-Things-Go-Wrong –

+0

是的,我已經看到了 –

回答

0

你見過由fpx006這裏給出的答案嗎? https://github.com/pyinstaller/pyinstaller/issues/2368我做了一個小的改動它,如下所示(也張貼在該線程)。

這添加到我的頂級urls.py

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT). 

我做了同樣的事情,讓我的媒體文件送達

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)' 

然後這兩個添加到我的規格文件,我的遷移文件夾沿着如下:

datas=[('filter/filter/core/migrations','filter/core/migrations'), 
('filter/media_root','media_root'),('filter/static','static_root')], 

,其中的核心是在THI唯一的應用程序的名稱s^Django項目,並且過濾器是該項目的名稱。這是一個黑客位,但應該讓你發佈你的Django應用程序的.exe和看見你美麗的造型。