Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why won't collectstatic copy my static files?

Tags:

static

django

I have a MyApp/static/MyApp directory.

When I run ./manage.py collectstatic, I expect the MyApp directory be copied to STATIC_ROOT, but it doesn't.

I have DownloadedApp/static/DownloadedApp as well and its copied to STATIC_ROOT fine.

What am I missing?

like image 215
eugene Avatar asked Jan 23 '13 04:01

eugene


3 Answers

What are the STATIC_ROOT, STATICFILES_FINDERS, and STATICFILES_DIRS in your settings.py?

When collectstatic is run, the default STATICFILES_FINDERS value django.contrib.staticfiles.finders.FileSystemFinder will collect your static files from any paths that you have in STATICFILES_DIRS.

The other default STATICFILES_FINDERS value django.contrib.staticfiles.finders.AppDirectoriesFinder will look in the /static/ folder of any apps in your INSTALLED_APPS.

All of the static files that are found will be placed in the specified STATIC_ROOT directory.

Check out this link to the collectstatic docs

And this link an explanation of the various static settings in settings.py

You can also use python manage.py findstatic to see which directories collectstatic will look in.

like image 140
Dan Hoerst Avatar answered Nov 19 '22 22:11

Dan Hoerst


That just happened to me and I accidentally put the app's static files directory in the .gitignore file. So on my local machine it got collected just fine, but in production the static files were actually missing (gitignored).

like image 42
Moritz Avatar answered Nov 20 '22 00:11

Moritz


just do this and make the naming convention same

STATIC_URL = '/static/'
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')

static directory contains all off your project assets

assets directory will create automatic when u run this cmd

python3 manage.py collectstatic

this will copy all static folder content into assets folder

hope this helps :)

like image 5
Krishna Jangid Avatar answered Nov 19 '22 23:11

Krishna Jangid