Django 3.2.8: 0 static files copied to '/static'

3.8k Views Asked by At

This error occurs when performing command python manage.py collectstatic:

0 static files copied to '/home/project'.

That means there is no changes and my static files already exist in the destination but in this folder only one file:

static/
      - staticfiles.json

But I want all my CSS, js, HTML for panel admin to be in it.

Django Settings:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "/static/")

STATICFILES_DIRS = (
    STATIC_ROOT,
) 

urls.py

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

I also tried these 1, 2 but no results were found.

2

There are 2 best solutions below

0
Marco On BEST ANSWER

Define all paths with STATICFILES_DIRS where Django will look for static files. For example:

STATICFILES_DIRS = [os.path.join(BASE_DIR, "templates/staticfiles")]

When you run collectstatic, Django will copy all found files in all your paths from STATICFILES_DIRS into STATIC_ROOT.

In your case, Django will copy all files to:

STATIC_ROOT = os.path.join(BASE_DIR, "/static/")

After that, your static files are accessible through your defined STATIC_URL URL. In your case:

STATIC_URL = '/static/'
2
Akash Nagtilak On

settings.py

import os
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')

urls.py

urlpatterns = [
    path('demo/',Demo.as_view(),name='demo')
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.STATIC_ROOT)

Add Your File in folder- static->demo_folder->staticfiles.json

python3 manage.py collecstatic