From a7b88b6270059bde6c0698cf8279fa32ab6c0397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Mineo?= Date: Fri, 7 May 2021 10:32:15 +0200 Subject: [PATCH] Fetch static from relative path too --- django_weasyprint/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/django_weasyprint/utils.py b/django_weasyprint/utils.py index bb96386..607b56c 100644 --- a/django_weasyprint/utils.py +++ b/django_weasyprint/utils.py @@ -31,7 +31,13 @@ def django_url_fetcher(url, *args, **kwargs): elif settings.STATIC_URL and url_path.startswith(settings.STATIC_URL): path = url_path.replace(settings.STATIC_URL, '', 1) - data['file_obj'] = open(find(path), 'rb') + found_path = find(path) + if not found_path: + path = Path( + settings.STATIC_ROOT / url_path.replace(settings.STATIC_URL, '', 1) + ) + found_path = f'{path}' if path.is_file() else None + data['file_obj'] = open(found_path, 'rb') return data # fall back to weasyprint default fetcher