Reputation: 101
I am working on a Django project utilizing Django Rest Framework for APIs. I've encountered an issue where the CSS is not loading for the browsable APIs. I am using Whitenoise to serve static files, but the problem persists.
Here’s the relevant part of my settings.py:
STATIC_LOCATION = "assets/"
MEDIA_LOCATION = "media/"
STATICFILES_DIRS = [
BASE_DIR / "assets",
]
STATIC_ROOT: str = "static"
MEDIA_ROOT: str = "media"
STATIC_URL = "/assets/"
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
#...
]
STORAGES = {
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
}
My custom css and js are stored in assets
dictory and i want to store correct static files in static
dir.
I've followed the standard configuration for Whitenoise, but its rendering a blank page without html and css for the DRF browsable API. I have also tried without whitenoise, and it is serving html file without statics(css and js).
Any suggestions or guidance on what might be going wrong or what else I should check would be greatly appreciated!
Upvotes: 2
Views: 37