Monday, June 18, 2018

Pyinstaller django static files not being used on Windows

Leave a Comment

I'm using PyInstaller to try and make running of a Django project simple for a user. It works perfectly on my Linux PC but when I try and create it on a Windows PC the static files are not loading and I cannot understand why.

I'm using the following .spec file to create the application.

# -*- 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') 

My static files are defined within settings.py as:

STATIC_URL = '/static/' STATICFILES_DIRS = (     os.path.join(BASE_DIR, "potential_waffle/static"), ) STATIC_ROOT = os.path.join(BASE_DIR, 'static') 

And I'm picking up the static files for runserver:

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

The program works fine and does everything it should except the formatting of the browser and within terminal I have the following:

[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 

The files are in the /static folder (I've checked) but it seems to be redirecting them to a location where the files do not exist (even though we get a 200 response).

I am guessing there is something wrong with the .spec file for Windows but I've tried changing the slashes every which way to no avail. I do get some warning messages during the build (which could be the issue) of the style:

WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:\users\henry\potential-waffle\env\scripts\python.exe

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment