WhyNotHugo / django-renderpdf

📄 Django app to render django templates as PDF files.
https://django-renderpdf.readthedocs.io/
ISC License
67 stars 7 forks source link

ImageField: not loading when developping locally #62

Open dannywillems opened 6 months ago

dannywillems commented 6 months ago

See https://github.com/WhyNotHugo/django-renderpdf/issues/5#issuecomment-1975244093

WhyNotHugo commented 6 months ago

Can you share an example of the template?

dannywillems commented 6 months ago

Take this as an example: https://stackoverflow.com/questions/45865205/imagefield-django-template, modulo the changes suggested in the answer. Let me know if you want a full example.

Alurith commented 6 months ago

I don't know if this can be a good solution but I had the same issue while serving statics locally, so I overrided the url_fetcher to fix it.

def url_fetcher(self, url):
    if "file://" in url:
        file_path = url.replace("file://", "", 1)
        if file_path:
            url = f"{self.request.scheme}://{self.request.get_host()}{file_path}"

    return super().url_fetcher(url)