Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django WeasyPrint CSS integration warning: Relative URI reference without a base URI: <link href="/static/css/bootstrap.min.css"> at line None

I want to generate reports using WeasyPrint in Django. But I don't know how to integrate the css (specifically the bootstrap css file). I am able to see the generated html. But I get a warning when I add this line to my template-

<link href="/static/css/bootstrap.min.css" rel="stylesheet"/>

The warning is - Relative URI reference without a base URI: at line None

I would like to know how to send the base URI to the template. Any help would be appreciated.

like image 281
aishpant Avatar asked Nov 24 '14 03:11

aishpant


1 Answers

I had to add base_url=request.build_absolute_uri(). So the print command looks like:

weasyprint.HTML(string=html,base_url=request.build_absolute_uri()).write_pdf(response)
like image 137
aishpant Avatar answered Oct 24 '22 16:10

aishpant