0
votes

This is my django project, there is two apps; polls and study

This is the setting of my static file settings.

STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR,"study","static","HScard"),
)
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")

I expected the 'python manage.py collectstatic' in the shell would copy static files to "staticfiles" from only in "study/static/HSCard"(due to STATICFILES_DIRS above).

However, "collectstatic" copied unexpected files below.

enter image description here

Why are the files in admin and polls copied to staticfiles?? besides the files in admin folder were from here (a single example):

Copying 'C:\ProgramData\Anaconda3\lib\site-packages\django\contrib\admin\static\admin\js\vendor\xregexp\xregexp.min.js'

Why does 'collectstatic' working like this and how can I fix it as I expected?

The version of django using is 2.0.7. Thank you.

1
These are the static files for Django Admin. - Josewails
@Josewails How can I avoid copying these files while excuting collectstatic? - Jinho Park
You mean you don't want to include admin dir?? - seuling
You can use python manage.py collectstatic --noinput -i admin - Josewails
@seuling Yes, but if it is necessary, It doesn't really matter to include them. More than that, I just want to know why STATICFILES_DIRS doesn't working as I know. I knew collectstatic copying the files from where is in STATICFILES_DIRS. Isn't it right? - Jinho Park

1 Answers

0
votes

The problem is due to the default Staticfiles Finders settings:

STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

The AppDirectoriesFinder will look through your apps listed in your INSTALLED_APPS setting. If there are files such as admin/static/, which are included in the admin by default, then they will also be found by collect_static. Your choices are to either:

  1. Remove apps from INSTALLED_APPS (obviously they won't work any more, but they won't contribute static files either)
  2. Add the STATICFILES_FINDERS setting as above, but without the AppDirectoriesFinder setting. Then Django will only collect staticfiles that you have explicitly mentioned in STATICFILES_DIRS