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

白昼怎懂夜的黑 提交于 2019-12-08 15:21:06

问题


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.


回答1:


Answering my own question. Yeah so this was ridiculously simple. All I had to do was 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)


来源:https://stackoverflow.com/questions/27097544/django-weasyprint-css-integration-warning-relative-uri-reference-without-a-base

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!