Skip to content

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

@mjmare

Description

@mjmare

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions