Reputation: 11
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.
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.
Upvotes: 0
Views: 240
Reputation: 1226
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:
AppDirectoriesFinder
setting. Then Django will only collect staticfiles that you have explicitly mentioned in STATICFILES_DIRSUpvotes: 0