drf-spectacular
drf-spectacular copied to clipboard
Missing staticfiles manifest entry for 'drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css'
Describe the bug We are trying to enable Swagger UI through Sidecar. SwaggerUI seems to work fine locally, but when we deploy it no longer works. We see the following stack trace:
Missing staticfiles manifest entry for 'drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css'
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/django/patch.py", line 213, in wrapped
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 55, in wrapped_view
return view_func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/trace_utils.py", line 162, in wrapper
return func(mod, pin, wrapped, instance, args, kwargs)
File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/django/patch.py", line 213, in wrapped
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 103, in view
return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/trace_utils.py", line 162, in wrapper
return func(mod, pin, wrapped, instance, args, kwargs)
File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/django/patch.py", line 213, in wrapped
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/trace_utils.py", line 162, in wrapper
return func(mod, pin, wrapped, instance, args, kwargs)
File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/django/restframework.py", line 19, in _traced_handle_exception
return wrapped(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
raise exc
File "/usr/local/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/trace_utils.py", line 162, in wrapper
return func(mod, pin, wrapped, instance, args, kwargs)
File "/usr/local/lib/python3.10/site-packages/ddtrace/contrib/django/patch.py", line 213, in wrapped
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/drf_spectacular/views.py", line 216, in get
'swagger_ui_css': self._swagger_ui_resource('swagger-ui.css'),
File "/usr/local/lib/python3.10/site-packages/drf_spectacular/views.py", line 180, in _swagger_ui_resource
return _get_sidecar_url(f'swagger-ui-dist/{filename}')
File "/usr/local/lib/python3.10/site-packages/drf_spectacular/views.py", line 118, in _get_sidecar_url
return static(f'drf_spectacular_sidecar/{filepath}')
File "/usr/local/lib/python3.10/site-packages/django/templatetags/static.py", line 179, in static
return StaticNode.handle_simple(path)
File "/usr/local/lib/python3.10/site-packages/django/templatetags/static.py", line 129, in handle_simple
return staticfiles_storage.url(path)
ValueError: Missing staticfiles manifest entry for 'drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css'
To Reproduce We have strict CSP rules so we are following the FAQ here: https://drf-spectacular.readthedocs.io/en/latest/faq.html#my-swagger-ui-and-or-redoc-page-is-blank.
Using:
drf-spectacular==0.26.1
drf-spectacular-sidecar==2023.12.1
Expected behavior Swagger UI loads correctly in our deployed site.
CSP is irrelevant for your issue. Are you absolutely sure you have installed the sidecar package in your deployed container? I strongly suspect you have not, because why would it work for you locally?
try this: python manage.py findstatic --verbosity 2 drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css
, which works fine for me.
@tfranzel when running that locally or in the deployed container, it's able to find it:
Found 'drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css' here:
/usr/local/lib/python3.10/site-packages/drf_spectacular_sidecar/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css
/app/staticfiles/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css
Looking in the following locations:
/app/merge/static
/usr/local/lib/python3.10/site-packages/rest_framework/static
/usr/local/lib/python3.10/site-packages/adminsortable/static
/usr/local/lib/python3.10/site-packages/versatileimagefield/static
/usr/local/lib/python3.10/site-packages/nested_admin/static
/usr/local/lib/python3.10/site-packages/drf_spectacular_sidecar/static
/usr/local/lib/python3.10/site-packages/colorfield/static
/usr/local/lib/python3.10/site-packages/django_extensions/static
/usr/local/lib/python3.10/site-packages/django/contrib/admin/static
/app/staticfiles
Sorry to say but it makes no sense. I believe you are comparing the wrong container, that is not really exactly what is deployed (flags?, conditional build?). Can't explain it otherwise, since you have it working locally.
@tfranzel I'm fairly certain I'm in the right container. Could there be any other setup steps that are required?
A few other notes, if they're helpful:
- I have also made sure to run
collectstatic
in the container, but that doesn't seem to help. - We have
STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
set - We are extending StaticFilesConfig when installing it:
class OurStaticFilesConfig(StaticFilesConfig):
"""Using this app in settings instead of django.contrib.staticfiles in order for these settings to take effect."""
if settings.ENVIRONMENT == Environment.local:
# Don't collect and serve rest_framework files outside of localhost. We don't use the DRF Browsable API
# in prod, and the version of jquery that our version of DRF uses was flagged as a vulnerability.
# It's easiest to just exclude rest_framework static files.
ignore_patterns = ["rest_framework/"]
logger.info(f"Ignoring static files of patterns: {ignore_patterns}")