Describe the bug
def _get_sidecar_url(package):
return f'{settings.STATIC_URL}drf_spectacular_sidecar/{package}'
This may fail when using STATICFILES_STORAGE with a non-default backend for which STATIC_URL is unused or is insufficient to describe the static file location. A more robust implementation would possibly be to use django.templatetags.static, i.e.:
from django.templatetags.static import static
def _get_sidecar_url(package):
return static(f'drf_spectacular_sidecar/{package}')
To Reproduce
Install django-storages and configure STATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" (etc.) in your project settings. Do not set STATIC_URL in your project settings. Verify that other static files are correctly loaded from S3, but SpectacularSwaggerView is attempting incorrectly to load the sidecar files from the relative path of /static/ instead of from the S3 server.
Expected behavior
When STATICFILES_STORAGE is configured, use staticfiles_storage.url() instead of STATIC_URL to construct the static file paths for sidecar files (just as django.templatetags.static.static() does).
Describe the bug
This may fail when using
STATICFILES_STORAGEwith a non-default backend for whichSTATIC_URLis unused or is insufficient to describe the static file location. A more robust implementation would possibly be to usedjango.templatetags.static, i.e.:To Reproduce
Install
django-storagesand configureSTATICFILES_STORAGE = "storages.backends.s3boto3.S3Boto3Storage"(etc.) in your project settings. Do not set STATIC_URL in your project settings. Verify that other static files are correctly loaded from S3, but SpectacularSwaggerView is attempting incorrectly to load the sidecar files from the relative path of/static/instead of from the S3 server.Expected behavior
When
STATICFILES_STORAGEis configured, usestaticfiles_storage.url()instead ofSTATIC_URLto construct the static file paths for sidecar files (just asdjango.templatetags.static.static()does).