我正在尝试从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
这告诉我我缺少了一些东西。如何使样式表可调用?谢谢。
您正在呼叫()中使用request
object作为网址提取程序。您不需要提供此参数来获取不需要身份验证的简单资源。weasyprint.HTML
url_fetcher=request
见这对URL取程序的详细信息。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句