1

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.

Saeed
  • 3,294
  • 5
  • 35
  • 52
  • `STATICFILES_DIRS` should not contain `STATIC_ROOT`, do you not get an error telling you that when you try to run `collectstatic`? – Iain Shelvington Dec 24 '21 at 12:32
  • @IainShelvington No. output is `0 static files copied to '/static'.` – Saeed Dec 24 '21 at 12:35
  • What output do you get from `python manage.py version`? You should remove the leading slash from the join for STATIC_ROOT, otherwise you set it to "/static" from the root of your filesystem: `STATIC_ROOT = os.path.join(BASE_DIR, "static")` – Iain Shelvington Dec 24 '21 at 12:43
  • Can you tell us the path where you have placed your assets? Normally, it's places somewhere in `/templates/staticfiles/`. – Marco Dec 24 '21 at 12:51
  • 1
    Hello @Saeed try to convert your ``STATICFILES_DIRS`` to list instead of tuple I know it's weird but when you run ``python manage.py collectstatic`` it's giving you path to your root directory instead it should give you path to your **STATIC_ROOT** eg. ***``0 static files copied to '/home/project/static'.``*** – Ankit Tiwari Dec 24 '21 at 14:16
  • @IainShelvington `python manage.py version` => `3.2.8` – Saeed Dec 24 '21 at 15:47
  • 1
    @AnkitTiwari Thank you for your answer. You were right. Some of my settings were wrong elsewhere. – Saeed Dec 24 '21 at 16:09

2 Answers2

1

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

Akash Nagtilak
  • 325
  • 1
  • 5
  • Without `STATICFILES_DIRS` in your settings.py file, django will not grab for your static assets. By the way, it should be `collectstatic` and not `collecstatic`. – Marco Dec 24 '21 at 14:05
  • Thanks for valuable information...In this some spelling mistakes.....!! Thank you – Akash Nagtilak Dec 25 '21 at 15:21
1

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/'
Marco
  • 2,371
  • 2
  • 12
  • 19