I packaged my django project with pyinstaller, my project tree is like below:
I did all bellow steps:
- Copy all static file into static/ with
python manage.py collectstatic - Add all static file in
.specfile like this:
datas=[
('remotescope/templates/remotescope/', 'remotescope/templates/remotescope'),
('static/', 'static'),
('remotescope/logging.conf', '.'),],
- Update
setting.pylike 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~
