why collectstatic won't copy my static files?

2019-03-18 15:58发布

I have 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?

标签: django static
5条回答
姐就是有狂的资本
2楼-- · 2019-03-18 16:20

This happened to me because while investigating a bug occurring on certain dates, changed my computer date and time.

Hence it disturbed things like collectstatic, and also my browser history.

Don't change your computer date and time.

查看更多
对你真心纯属浪费
3楼-- · 2019-03-18 16:25

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.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-03-18 16:29

I was under the impression the comparison would be content based. It turned out to be date based. So, don't mess with your files after collecstatic.

查看更多
地球回转人心会变
5楼-- · 2019-03-18 16:33

One Quick work-around, although this does not fix it or explain WHY it's happening, is to:

  1. go to your project's file directory & rename your project's 'static' folder to something else like 'static-old'
  2. create a new,empty folder called 'static' in your project directory
  3. now if you run python manage.py collectstatic it will see that nothing is in your static folder and will copy ALL static files over.
查看更多
ら.Afraid
6楼-- · 2019-03-18 16:36

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).

查看更多
登录 后发表回答