我正在使用PyInstaller尝试为用户简单地运行Django项目。它在我的Linux PC上运行得很好但是当我尝试在Windows PC上创建它时,静态文件没有加载,我无法理解为什么。
我正在使用以下.spec
文件来创建应用程序。
# -*- mode: python -*-
block_cipher = None
a = Analysis(['manage.py'],
pathex=['C:\\Users\\henry\\potential-waffle'],
binaries=[("C:/Program Files (x86)/Windows Kits/10/Redist/ucrt/DLLs/arm", '.')],
datas=[('media','media'),('potential_waffle/static','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='webscraper',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='webscraper')
我的静态文件在settings.py
中定义为:
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "potential_waffle/static"),
)
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
我正在选择runserver
的静态文件:
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
该程序运行正常,除了浏览器的格式和终端内我应该做的一切我有以下内容:
[08/Jun/2018 12:00:57] "GET /login/?next=/ HTTP/1.1" 200 5438
[08/Jun/2018 12:00:57] "GET /static/agency/vendor/bootstrap/css/bootstrap.min.css HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/font-awesome/css/font-awesome.min.css HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/css/agency.css HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/toastr/toastr.min.css HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/js/cookiechoices.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/vendor/jquery/jquery.min.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/vendor/bootstrap/js/bootstrap.min.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/js/jqBootstrapValidation.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/js/contact_me.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/agency/js/agency.min.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /static/toastr/toastr.min.js HTTP/1.1" 302 0
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/vendor/bootstrap/css/bootstrap.min.css HTTP/1.1" 200 5490
[08/Jun/2018 12:00:57] "GET /login/?next=/static/font-awesome/css/font-awesome.min.css HTTP/1.1" 200 5482
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/css/agency.css HTTP/1.1" 200 5466
[08/Jun/2018 12:00:57] "GET /login/?next=/static/js/cookiechoices.js HTTP/1.1" 200 5464
[08/Jun/2018 12:00:57] "GET /login/?next=/static/toastr/toastr.min.css HTTP/1.1" 200 5466
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/vendor/jquery/jquery.min.js HTTP/1.1" 200 5479
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/vendor/bootstrap/js/bootstrap.min.js HTTP/1.1" 200 5488
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/js/jqBootstrapValidation.js HTTP/1.1" 200 5479
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/js/contact_me.js HTTP/1.1" 200 5468
[08/Jun/2018 12:00:57] "GET /login/?next=/static/agency/js/agency.min.js HTTP/1.1" 200 5468
[08/Jun/2018 12:00:57] "GET /login/?next=/static/toastr/toastr.min.js HTTP/1.1" 200 5465
这些文件位于/static
文件夹中(我已经检查过),但似乎是将它们重定向到文件不存在的位置(即使我们得到200响应)。
我猜测Windows的.spec文件有问题,但是我试图改变斜线,但每一种方式都无济于事。我在样式的构建期间(可能是问题)得到一些警告消息:
WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:\users\henry\potential-waffle\env\scripts\python.exe