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

catch url fetcher exception for serving static files #422

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion utils/url_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
from urllib.parse import urlparse

from django.conf import settings
from django.contrib.staticfiles.finders import find
from django.contrib.staticfiles.storage import staticfiles_storage
from django.core.exceptions import ImproperlyConfigured
from django.core.files.storage import default_storage
from django.urls import get_script_prefix

Expand Down Expand Up @@ -62,7 +64,10 @@ def django_url_fetcher(url): # pragma: no cover

elif settings.STATIC_URL and url_path.startswith(settings.STATIC_URL):
path = url_path.replace(settings.STATIC_URL, '', 1)
data['file_obj'] = staticfiles_storage.open(path)
try:
data['file_obj'] = staticfiles_storage.open(path)
except ImproperlyConfigured:
data['file_obj'] = open(find(path), 'rb')
return data

# Fall back to weasyprint default fetcher
Expand Down