我使用django和weasyprint制作了一个应用程序,该应用程序打印带有图片的pdf文件和设计我的pdf文件的css文件。我使用nginx、gunicorn和supervisor来部署我的应用程序。在我的内联网中一切都很好。当我使用INTERNET PUBLIC IP ADDRESS在互联网上发布它时,我的pdf文件不再显示图片和css设计。但是应用程序的所有静态文件都能正常工作我看到了我的枪骨日志,但什么也没看到。我使用Nginx来提供我的静态文件。这是配置
上游应用程序服务器{服务器unix:/webapps/myapp/run/gunicorn.sock fail_timeout=0;}
服务器{
听80;
服务器名称127.0.0.1;
客户端_max_body_size 4G;
access_log/webapps/myapp/logs/nginix-access.log;
error_log/webapps/myapp/logs/nginix-error.log;
位置/静态/{alias/webapps/myapp/basegenecirdes/public/static/;}
位置/媒体/{alias/webapps/myapp/media/;}
位置/{proxy_set_header X-Forwarded-For$proxy_add_X_forwardd_For;proxy_set_header主机$http_Host;proxy_redirect关闭;
if (!-f $request_filename) { proxy_pass http://app_server; break; }
}
在我的视图中。要调用pdf文件,我使用这个
html=render_to_string('pdf/print.html',{'pagesize':'A4'}(response=HttpResponse(content_type="application/pdf",(response['Content-Disposition']='inline;filename="print.pdf"'黄鼬纹。HTML(string=HTML,base_url=request.build_absolute_uri(((.write_pdf(response(
返回response
静态图像文件:
<img style="background-color: white" src="{% static "image/photo_50x48.png" %}">
媒体图像文件
<img alt="{{ a.nom }}" src="{{ a.photo.thumbnail.url }}" >
有人有同样的问题吗?
阅读您的编辑后,这个问题似乎是使用Weasyprint不显示图像(Django(的PDF输出的副本
你的代码中已经有了答案的第一部分。但我在你的write_pdf()
电话中看不到这一部分:
对于要在PDF上显示的HTML样式,请根据Weasyprint文档添加presentational_hints=True:
pdf = html.write_pdf(stylesheets=[CSS(settings.STATIC_ROOT + '/css/detail_pdf_gen.css')], presentational_hints=True);