checks.py 846 B

1234567891011121314151617181920212223242526272829
  1. from django.conf import STATICFILES_STORAGE_ALIAS, settings
  2. from django.contrib.staticfiles.finders import get_finders
  3. from django.core.checks import Error
  4. E005 = Error(
  5. f"The STORAGES setting must define a '{STATICFILES_STORAGE_ALIAS}' storage.",
  6. id="staticfiles.E005",
  7. )
  8. def check_finders(app_configs=None, **kwargs):
  9. """Check all registered staticfiles finders."""
  10. errors = []
  11. for finder in get_finders():
  12. try:
  13. finder_errors = finder.check()
  14. except NotImplementedError:
  15. pass
  16. else:
  17. errors.extend(finder_errors)
  18. return errors
  19. def check_storages(app_configs=None, **kwargs):
  20. """Ensure staticfiles is defined in STORAGES setting."""
  21. errors = []
  22. if STATICFILES_STORAGE_ALIAS not in settings.STORAGES:
  23. errors.append(E005)
  24. return errors