如何修复 function/symbol 'pango_context_set_round_glyph_positions' 错误

How to fix function/symbol 'pango_context_set_round_glyph_positions' error

我已经使用 Apache2 部署了一个 Django 项目,除了为表单创建 PDF 文件的 weazyprint 之外,一切正常。 pdf 在测试和本地主机上运行良好。

现在每次访问 pdf 时都会显示此错误:

FileNotFoundError at /business_plan/businessplan/admin/info/2/pdf/
[Errno 2] No such file or directory: '/home/ahesham/Portfolio/static\css\report.css'

我尝试更改 \ 并添加了两次,但没有成功 这是 views.py

def admin_order_pdf(request, info_id):
    info = get_object_or_404(Info, id=info_id)
    html = render_to_string('businessplan/pdf.html', {'info': info})
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'filename="order_{}.pdf"'.format(
        Info.id)
    weasyprint.HTML(string=html,base_url=request.build_absolute_uri()).write_pdf(response,
                                           stylesheets=[weasyprint.CSS(settings.STATICFILES_DIRS[0] + '\css\report.css')], presentational_hints=True)
    return response

错误来自此 \css\report.css 知道 report.css 文件位于静态文件夹中,所有 css 和 deplyed 站点的 js 工作正常,我试过了python manage.py collectstatic 无效。

我不确定为什么显示错误是因为 ubunto 还是 django 视图。

更新:

我尝试将位置更改为如下:

stylesheets=[weasyprint.CSS(settings.STATICFILES_DIRS[0] + '/css/report.css')], presentational_hints=True) 

这是出现的错误

function/symbol 'pango_context_set_round_glyph_positions' not found in library 'libpango-1.0.so.0': /usr/lib/x86_64-linux-gnu/libpango-1.0.so.0: undefined symbol: pango_context_set_round_glyph_positions

所以我搜索了解决方案并尝试下载这个包:

sudo apt-get install libpango1.0-0

也尝试过:

install libpango1.0-dev

但仍然没有任何改变它不会工作得到同样的错误。

我也试过在部署项目时用静态根目录替换静态目录购买我得到了同样的错误function/symbol 'pango_context_set_round_glyph_positions'如下:

stylesheets=[weasyprint.CSS(settings.STATIC_ROOT + '/css/report.css')]

这是设置文件:

STATIC_URL = '/static/'
#if DEBUG:
#    STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
#else:
#STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static' )]

MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

我正在使用 Ubuntu 18.04 LTS 磁盘 - Apache2 服务器

我的问题: 我做错了什么,我该如何解决?

如果需要其他信息来帮助修复此错误,请告诉我。

如果有其他方法可以在 Django admin 中显示 PDF,我们将不胜感激

可能是 Weasyprint 没有正确下载:

尝试:

pip install django-weasyprint

来源:https://pypi.org/project/django-weasyprint/

我也遇到过同样的错误

'pango_context_set_round_glyph_positions' not found in library

我想你一定是在使用 weasyprint 版本 53.0,它需要 pango 版本 1.44.0+

将 weasyprint 版本降级到 52.5 解决了我的问题 issue.because 这不需要最新版本的 pango。

你也可以查看这个https://github.com/Kozea/WeasyPrint/issues/1384