14

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.

2
  • Did you add rest_framework to your INSTALLED_APPS? Commented Aug 18, 2022 at 17:01
  • yes its in my INSTALLED_APPS Commented Aug 18, 2022 at 17:33

2 Answers 2

25

Update: DRF 3.14.0 now supports Django 4.1. If you've added stubs to static as per below, be sure to remove them.

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.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks! If I change to Django 4.0 it works
For any future readers. This is still the case.
The latest version of Django Rest Framework finally supports Django 4.1 django-rest-framework.org/community/release-notes/#314x-series
I am using Django 4.1.1 and adding the empty files worked for me
Looks like this is still an issue with Django 4.2
0

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")
]

3 Comments

If I change the settings like this I get a django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path. if I set STATIC_ROOT = BASE_DIR / "static", I get The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting. if I set STATIC_ROOT = BASE_DIR / "staticfiles", again I get The CSS file 'rest_framework/css/bootstrap.min.css' references a file which could not be found: rest_framework/css/bootstrap.min.css.map
What version of Django are you using, this setting works for from version 2, and I have used it for version 4.0
I used Version 4.1. I tried now with 4.0 and is working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.