Django miss static files after packaging with pyinstaller

19 views Asked by At

I packaged my django project with pyinstaller, my project tree is like below:

enter image description here

I did all bellow steps:

  1. Copy all static file into static/ with python manage.py collectstatic
  2. Add all static file in .spec file like this:
datas=[
('remotescope/templates/remotescope/', 'remotescope/templates/remotescope'),
('static/', 'static'),
('remotescope/logging.conf', '.'),],
  1. Update setting.py like this:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

But when I try to run my executable file with command of ./RemoteScope runserver 0.0.0.0:8000 --noreload, it info that all static files not found like bellow:

2024-03-30 09:35:51,125 - 139621882558208 - django.request - WARNING - Not Found: /static/admin/css/base.css
[30/Mar/2024 09:35:51] "GET /static/admin/css/nav_sidebar.css HTTP/1.1" 404 2288
...
2024-03-30 09:35:51,134 - 139621795096320 - django.request - WARNING - Not Found: /static/admin/css/login.css
[30/Mar/2024 09:35:51] "GET /static/admin/css/login.css HTTP/1.1" 404 2270

This is the urls.py of my project

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

urlpatterns = [
    path('admin/', admin.site.urls),
    path('remotescope/', include('remotescope.urls')),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) # Static files will supplied by Django

BTW: Everything is good in debug mode wiht cmd of "python manage.py runserver 0.0.0.0:8000"(Need modify the setting.py)

Anybody has some advice? Thank u very much~

0

There are 0 answers