python - 如何修复函数/符号 'pango_context_set_round_glyph_positions' 错误

标签 python django apache ubuntu django-views

我已经使用 Apache2 部署了一个 Django 项目,一切正常,除了 weazyprint 为表单创建 PDF 文件。 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 和js 工作正常,我尝试了python manage.py collectstatic不工作。
我不确定为什么显示错误是因为 ubunto 或 django View 。
更新:
我尝试将位置更改为如下:
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,任何反馈都将不胜感激

最佳答案

我也遇到了同样的错误

'pango_context_set_round_glyph_positions' not found in library


我认为您必须使用 weasyprint 版本 53.0,它需要 pango 版本 1.44.0+
将 weasyprint 版本降级到 52.5 解决了我的问题。因为这不需要最新版本的 pango。
您也可以查看 https://github.com/Kozea/WeasyPrint/issues/1384

关于python - 如何修复函数/符号 'pango_context_set_round_glyph_positions' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68720486/

相关文章:

javascript - 从 Python 上的 post 方法获取变量

Django Python 将文件上传到特定文件夹

apache - Web 套接字的 apache 代理配置问题

Python - scapy 数据包大小差异

python - 按 Django ORM 分组

python - 在表单 django-allauth app 的末尾显示 google recaptcha

python - Django:使用Redis做Cache超时的含义

php - 500 内部服务器错误...特定于浏览器?

php - 如何放宽 PHP 的 open_basedir 限制?

python - 设置缺少元素的字符串格式 - Python