我正在尝试从 django 输出 pdf。我正在使用 weasyprint。这是我的看法:
def fleet_report_pdf(request):
template = loader.get_template("Reports/fleetreport.html")
context = {
'crews': models.Unit.objects.all().annotate(c=Count('memberunit__Member')),
's31': models.Member.objects.filter(memberunit__isnull=True)
}
html = template.render(RequestContext(request, context))
response = HttpResponse(content_type="application/pdf")
weasyprint.HTML(string=html, base_url=request.build_absolute_uri(), url_fetcher=request).write_pdf(response)
return response
然而,pdf加载,页面没有样式。进一步挖掘时,我在控制台中注意到如下错误:
Failed to load stylesheet at http://127.0.0.1:8000/static/css/layout.css : TypeError: 'WSGIRequest' object is not callable
Failed to load stylesheet at http://127.0.0.1:8000/static/css/darkblue.css : TypeError: 'WSGIRequest' object is not callable
Failed to load stylesheet at http://127.0.0.1:8000/static/css/custom.css : TypeError: 'WSGIRequest' object is not callable
这告诉我我错过了一些东西。如何使样式表可调用?谢谢。