WeasyPrint HTML to PDF**504网关超时**使用NGINX Djang

2024-04-29 08:49:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Django+WeasyPrint生成HTML到PDF

在HTML模板中,我有大约10个SVG文件。在本地服务器上运行时,将HTML转换为PDF需要15秒。而在测试服务器(使用NGINX运行)中,它会超时。在WeasePrint中,我提到了我的测试URL(http//TEST.sampleproject)。com:8000)在基本url中。一旦我删除了基本的url,它会很快做出响应。但是图像没有加载

我的密码

html_string = render_to_string('sample.html', {'data': data})
result = HTML(string=html_string, base_url='http//test.sampleproject.com:8000').write_pdf(presentational_hints=True)
response = HttpResponse(result, content_type='application/pdf')
response['Content-Disposition'] = 'inline; filename={}'.format('sample.pdf')
return response

在我的模板文件中,我加载了大约10个图像。例如:“sample.html”模板文件:

  <img src="{% static 'svg/Logo1.svg' %}" alt="" />
  <img src="{% static 'svg/Logo2.svg' %}" alt="" />

在Docker容器中运行时抛出“504网关超时”

请帮我解决这个问题


Tags: 文件samplesvgsampleproject服务器com模板http