django-renderpdf icon indicating copy to clipboard operation
django-renderpdf copied to clipboard

ImageField: not loading when developping locally

Open dannywillems opened this issue 4 months ago • 3 comments

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

dannywillems avatar Mar 03 '24 17:03 dannywillems

Can you share an example of the template?

WhyNotHugo avatar Mar 03 '24 18:03 WhyNotHugo

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.

dannywillems avatar Mar 03 '24 18:03 dannywillems

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)

Alurith avatar Mar 19 '24 17:03 Alurith