Skip to content

Commit

Permalink
ensure DJANGO_VITE_STATIC_URL_PREFIX ends with a slash (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
thijskramer authored Jun 2, 2023
1 parent 0717681 commit dfe8f32
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions django_vite/templatetags/django_vite.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,14 +456,17 @@ def _generate_production_server_url(path: str) -> str:
str -- Full URL to the asset.
"""

prefix = DJANGO_VITE_STATIC_URL_PREFIX
if not DJANGO_VITE_STATIC_URL_PREFIX.endswith("/"):
prefix += "/"
production_server_url = urljoin(prefix, path)

if apps.is_installed("django.contrib.staticfiles"):
from django.contrib.staticfiles.storage import staticfiles_storage

return staticfiles_storage.url(
urljoin(DJANGO_VITE_STATIC_URL_PREFIX, path)
)
else:
return urljoin(DJANGO_VITE_STATIC_URL_PREFIX, path)
return staticfiles_storage.url(production_server_url)

return production_server_url


@register.simple_tag
Expand Down

0 comments on commit dfe8f32

Please sign in to comment.