djangodjango-admincollectstaticdjango-static

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


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.


Solution

  • 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/'