问题描述
在将模板导出到PDF时,我正在努力正确使用Django WeasyPrint。
此问题仅在PythonAnywhere版本上发生,使用localhost
上的视图可按预期工作。在PythonAnywhere上将任何其他视图与相同的样式表一起使用也可以正常工作。
加载这两个资源时发生错误:
<link rel="stylesheet" href="{% static 'css/boostrap4.5.2.css' %}">
<link rel="stylesheet" href="{% static 'css/blog.css' %}">
(注意:我最初使用CDN作为引导CSS,但是当WeasyPrint尝试获取它时却发现了403禁止的错误,放弃了该错误)
这是weasyprint尝试使用它时的错误日志:
Failed to load stylesheet at http://kirkmania.pythonanywhere.com/static/css/boostrap4.5.2.css : timeout: timed out
Failed to load stylesheet at http://kirkmania.pythonanywhere.com/static/css/blog.css : timeout: timed out
这是服务器日志:
SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /cv/export (ip 10.0.0.52) !!!
uwsgi_response_writev_headers_and_body_do(): Broken pipe [core/writer.c line 306] during GET /cv/export (10.0.0.52)
SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /static/css/boostrap4.5.2.css (ip 10.0.0.52) !!!
uwsgi_response_write_headers_do(): Broken pipe [core/writer.c line 248] during GET /static/css/boostrap4.5.2.css (10.0.0.52)
SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request /static/css/blog.css (ip 10.0.0.52) !!!
uwsgi_response_write_headers_do(): Broken pipe [core/writer.c line 248] during GET /static/css/blog.css (10.0.0.52)
我还没有与wsgi的东西进行交互,说实话,这一切是怎么回事。我认为它已经达到Weasyprint url_fetcher
上的10秒超时了,这本不应该。
这是我的weasyprint查看代码:
class ExportPDF(WeasyTemplateView):
template_name='online_cv/export.html'
def get_context_data(self,**kwargs):
context = super(ExportPDF,self).get_context_data(**kwargs)
self.educations = cvEducation.objects.filter(user=self.request.user).order_by('-start_date')
self.jobs = cvWorkHistory.objects.filter(user=self.request.user).order_by('-start_date')
...
context['educations'] = self.educations
context['jobs'] = self.jobs
...
return context
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)