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

Django-renderpdf not compatible with Django S3 storage. #63

Open
mjmare opened this issue Mar 27, 2024 · 3 comments · May be fixed by #64
Open

Django-renderpdf not compatible with Django S3 storage. #63

mjmare opened this issue Mar 27, 2024 · 3 comments · May be fixed by #64

Comments

@mjmare
Copy link

mjmare commented Mar 27, 2024

Hi

I store all my static and media files on DigitalOcean Spaces (=S3 compatible). Normally this works fine.
I noticed however that a static image is not rendered in the pdf.
I turned on weasyprint logging and got this:

Step 1 - Fetching and parsing HTML - HTML string
Step 2 - Fetching and parsing CSS - CSS string
Step 2 - Fetching and parsing CSS - https://fonts.googleapis.com/css2?family=Exo:ital,wght@0,300;0,500;0,600;1,600&display=swap
Failed to load stylesheet at https://fonts.googleapis.com/css2?family=Exo:ital,wght@0,300;0,500;0,600;1,600&display=swap : AttributeError: 'StaticStorage' object has no attribute 'base_url'
Step 3 - Applying CSS
Ignored `mix-blend-mode:normal` at 1:11, unknown property.
Ignored `fill:#cccccc` at 1:11, unknown property.
Ignored `fill:#999999` at 1:11, unknown property.
Step 4 - Creating formatting structure
Failed to load image at 'https://ams3.digitaloceanspaces.com/cumulus-consult/static/images/logo.png?AWSAccessKeyId=DO007CFECQDF3ZG2KPAL&Signature=3cEjatZklzwowveTRdpBBviEb%2B8%3D&Expires=1711564413': AttributeError: 'StaticStorage' object has no attribute 'base_url'
Step 5 - Creating layout - Page 1
Step 6 - Creating PDF

The offending line is in helpers.py.:

 if url.startswith(staticfiles_storage.base_url):

base_url is not a valid property of the storage (which I have configured as S3Storage).
The error is caught silently.

I was not able to work around this problem (tried a custom url_fetcher), so in the end I just embedded an SVG in the page.

TIA

WhyNotHugo added a commit that referenced this issue Mar 31, 2024
@WhyNotHugo
Copy link
Owner

The error is caught silently.

Yeah, weasyprint silences all errors, which can be a bit annoying to debug.

@WhyNotHugo WhyNotHugo linked a pull request Mar 31, 2024 that will close this issue
@WhyNotHugo
Copy link
Owner

Can you try #64 ?

@mjmare
Copy link
Author

mjmare commented Apr 14, 2024

Sorry, don't know how to apply this change without a new release. I'm just a simple user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants