Home:ALL Converter>Pyinstaller compiles but 404 error on Django Static javascript files

Pyinstaller compiles but 404 error on Django Static javascript files

Ask Time:2018-06-23T03:31:02         Author:user1470034

Json Formatter

I've managed to get my applications to compile, but anytime it references a static file I receive a 404 error on my javascript files. I verified they do exist in the dist application.

My application structure is setup as the following:

enter image description here

I've added my static files to the datas of the .spec file as shown below:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['manage.py'],
             pathex=['C:\\python\\dsssecurity'],
             binaries=[],
             datas=[('mysite/static','static_root'),('mysite/search/templates','mysite/templates')],
             hiddenimports=['django_select2.apps','django.contrib.admin.apps','django.contrib.auth.apps','django.contrib.contenttypes.apps','django.contrib.sessions.apps','django.contrib.messages.apps','django.contrib.staticfiles.apps','django_filters.apps','widget_tweaks.apps','django.contrib.messages.middleware.apps','django.template.loaders.apps'],
             hookspath=['C:/Python/dsssecurity'],
             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='dsssecurity',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='dsssecurity')

I've also added the static settings to my mysite > search > urls.py as shown below:

from django.conf.urls import url, include
from django.contrib import admin
from . import views
from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
    url(r'^results/$', views.results, name='results'),
    url(r'^submitted/$', views.submitted, name='submitted'),
    url(r'^update/$', views.update, name='update'),
    url(r'^submittedupdate/$', views.submittedupdate, name='submittedupdate'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

my output of the console shows:

[22/Jun/2018 14:24:02] "GET /search/?employeentname=&employeelastname=&qv_statusid=1&employee_status_id=1&title=&coid= HTTP/1.1" 200 841390
[22/Jun/2018 14:24:10] "POST /search/results/ HTTP/1.1" 200 36667
Not Found: /static/search/selectallrep.js
Not Found: /static/search/selectall.js
Not Found: /static/search/rolebased.js
[22/Jun/2018 14:24:10] "GET /static/search/selectall.js HTTP/1.1" 404 2354
Not Found: /static/search/buttonsubmit.js
[22/Jun/2018 14:24:10] "GET /static/search/selectallrep.js HTTP/1.1" 404 2363
[22/Jun/2018 14:24:10] "GET /static/search/rolebased.js HTTP/1.1" 404 2354
[22/Jun/2018 14:24:10] "GET /static/search/buttonsubmit.js HTTP/1.1" 404 2363
Not Found: /static/search/buttonsubmit.js
[22/Jun/2018 14:24:10] "GET /static/search/buttonsubmit.js HTTP/1.1" 404 2363
Not Found: /static/search/selectall.js
[22/Jun/2018 14:24:10] "GET /static/search/selectall.js HTTP/1.1" 404 2354
Not Found: /static/search/selectallrep.js
[22/Jun/2018 14:24:10] "GET /static/search/selectallrep.js HTTP/1.1" 404 2363
Not Found: /static/search/rolebased.js
[22/Jun/2018 14:24:10] "GET /static/search/rolebased.js HTTP/1.1" 404 2354

I've followed instructions shown here:

Location of static files when creating a Django exe using pyinstaller

and

https://github.com/pyinstaller/pyinstaller/issues/2348

My static_url and staticfiles_dirs in settings is defined as:

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'mysite/static'),
)

My application works fine when running manage.py stand alone. What am I missing to get my static files to be recognized in my pyinstaller executable?

Author:user1470034,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/50994520/pyinstaller-compiles-but-404-error-on-django-static-javascript-files
yy