Skip to content

Staticfiles in TemplatesPanel aren't allowing viewing static file content #2160

@tim-schilling

Description

@tim-schilling

The static files panel is rendering the used static files with empty href="" attributes:

Image

When functioning properly, it should look like:

Image

Suggested solution:

staticfiles.py

def generate_stats(self, request, response):
    self.record_stats(
        {
            "num_found": self.num_found,
            "num_used": len(self.used_paths),
            # We can't store a dataclass, so we should convert it to a dictionary when it gets stored.
            "staticfiles": [{**vars(staticfile), "real_path": staticfile.real_path()} for staticfile in sorted(self.used_paths)],
            "staticfiles_apps": self.get_staticfiles_apps(),
            "staticfiles_dirs": self.get_staticfiles_dirs(),
            "staticfiles_finders": self.get_staticfiles_finders(),
        }
    )

staticfiles.html

<h4>{% blocktranslate count staticfiles_count=staticfiles|length %}Static file{% plural %}Static files{% endblocktranslate %}</h4>
{% if staticfiles %}
  <dl>
    {% for staticfile in staticfiles %}
      {# Ideally we'd use remoteCall to inject the content, but for now let's open the content in a separate tab/window #}
      {# We also need to explicitly render the path as we want to see it. Not use the __str__ method #}
      <dt><strong><a class="toggleTemplate" target="_blank" href="{{ staticfile.url }}">{{ staticfile.path }}</a></strong></dt>
      <dd><samp>{{ staticfile.real_path }}</samp></dd>
    {% endfor %}
  </dl>
{% else %}
  <p>{% translate "None" %}</p>
{% endif %}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy