Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper support for static URLs and django.contrib.staticfiles.storage.ManifestStaticFilesStorage #616

Open
stefan6419846 opened this issue May 22, 2024 · 0 comments

Comments

@stefan6419846
Copy link

I am using locally hosted CSS and Javascript files, served through the regular staticfiles app. Unfortunately, django-bootstrap5 does not seem to support this due to the custom tag logic:

@register.simple_tag
def bootstrap_css():
"""
Return HTML for Bootstrap CSS, or empty string if no CSS url is available.
Default value: ``None``
This value is configurable, see Settings section
**Tag name**::
bootstrap_css
**Usage**::
{% bootstrap_css %}
**Example**::
{% bootstrap_css %}
"""
rendered_urls = []
if bootstrap_css_url():
rendered_urls.append(render_link_tag(bootstrap_css_url()))
if bootstrap_theme_url():
rendered_urls.append(render_link_tag(bootstrap_theme_url()))
return mark_safe("".join([url for url in rendered_urls]))
@register.simple_tag
def bootstrap_javascript():
"""
Return HTML for Bootstrap JavaScript, or empty string if no JavaScript URL is available.
Adjust url in settings.
If no url is returned, we don't want this statement to return any HTML. This is intended behavior.
Default value: False
This value is configurable, see Settings section. Note that any value that evaluates to True and is
not "slim" will be interpreted as True.
**Tag name**::
bootstrap_javascript
**Usage**::
{% bootstrap_javascript %}
**Example**::
{% bootstrap_javascript %}
"""
# List of JS tags to include
javascript_tags = []
# Bootstrap JavaScript
bootstrap_js_url = bootstrap_javascript_url()
if bootstrap_js_url:
javascript_tags.append(render_script_tag(bootstrap_js_url))
# Join and return
return mark_safe("\n".join(javascript_tags))

The corresponding implementation at https://github.com/zostera/django-bootstrap5/blob/main/src/django_bootstrap5/html.py does not seem to work well with https://docs.djangoproject.com/en/5.0/ref/contrib/staticfiles/#manifeststaticfilesstorage as the hash is not really known when evaluating the settings. For this reason, I either have to use my own logic/template tags or monkey-patch the render_tag function, which both does not feel right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant