Home > Software engineering >  python manage.py collectstatic error: cannot find rest_framework bootstrap.min.css.map (from book &#
python manage.py collectstatic error: cannot find rest_framework bootstrap.min.css.map (from book &#

Time:08-19

I am reading the book 'Django for APIs' from 'William S. Vincent' (current edition for Django 4.0)

In chapter 4, I cannot run successfully the command python manage.py collectstatic.

I get the following error:

Traceback (most recent call last):
  File "/Users/my_name/Projects/django/django_for_apis/library/manage.py", line 22, in <module>
    main()
  File "/Users/my_name/Projects/django/django_for_apis/library/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/Users/my_name/Projects/django/django_for_apis/library/.venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/Users/my_name/Projects/django/django_for_apis/library/.venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/my_name/Projects/django/django_for_apis/library/.venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/my_name/Projects/django/django_for_apis/library/.venv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "/Users/my_name/Projects/django/django_for_apis/library/.venv/lib/python3.10/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 209, in handle
    collected = self.collect()
  File "/Users/my_name/Projects/django/django_for_apis/library/.venv/lib/python3.10/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 154, in collect
    raise processed
whitenoise.storage.MissingFileError: The file 'rest_framework/css/bootstrap.min.css.map' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x102fa07f0>.

The CSS file 'rest_framework/css/bootstrap.min.css' references a file which could not be found:
  rest_framework/css/bootstrap.min.css.map

Please check the URL references in this CSS file, particularly any
relative paths which might be pointing to the wrong location. 

I have the exact same settings like in the book in settings.py:

STATIC_URL = "static/"
STATICFILES_DIRS = [BASE_DIR / "static"]  # new
STATIC_ROOT = BASE_DIR / "staticfiles"  # new
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"  # new

I couldn't find any explanation for it. maybe someone can point me in the right direction.

CodePudding user response:

You have STATIC_ROOT pointing to BASE_DIR / "staticfiles" and then STATIC_URL = "static/". Make them point to the same static folder like this.

STATIC_URL = '/static/'
STATIC_DIR = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [

    os.path.join(BASE_DIR, "static")
]

CodePudding user response:

This appears to be related to Django 4.1: either downgrade to Django 4.0 or simply create the following empty files in one of your static directories:

static/rest_framework/css/bootstrap-theme.min.css.map
static/rest_framework/css/bootstrap.min.css.map

There's a recent change to ManifestStaticFilesStorage where it now attempts to replace source maps with their hashed counterparts.

Django REST framework has only recently added the bootstrap css source maps but is not yet released.

  • Related