python - Django > xhtml2pdf > 让它工作?

标签 python django xhtml2pdf

我在理解应该如何安装 xhtml2pdf 时遇到问题。我已按照 Chris Glass's 中的说明进行操作站点并设置虚拟环境并运行单元测试。当我在 views.py 文件的顶部插入以下内容时:

import ho.pisa as pisa
import cStringIO as StringIO
import cgi
import os

我收到一条错误消息,提示 No module named ho.pisa (如我所料)。我如何让 django 甚至 python 命令行导入这个模块(因为我已经尝试在命令行中导入模块并取得了相同的成功)

编辑

为什么我需要虚拟环境。我不能将 xhtml2pdf 作为一个包安装并正常导入,否则我会破坏一些 Django/python 的东西吗?

编辑

我还从 xhtml2pdf 虚拟环境中运行了 django > (xhtml2pdfenv)person@person-laptop:~/Software/django$ ./manage.py runserver 但它仍然拒绝导入 xhtm2pdf

最佳答案

我只是尝试使用 pip 安装 xhtml2pdf,而不是软件包。

pisa 模块在 xhtml2pdf 中,而不是 ho

>>> import xhtml2pdf.pisa as pisa

关于python - Django > xhtml2pdf > 让它工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8211386/

相关文章:

python - 在 pandas 数据框中逐行计算 CAGR?

python - Django:如何在运行测试后保持没有数据的数据库结构?

django - 在 Django 模板中访问 ImageField 上的图像尺寸?

python - 将 django_xhtml2pdf 与 django 1.1 一起使用 1"error: context must be a dict rather than Context."

python - 在 python 中使用 "*"

python - 使用 Chaquopy 安装 TensorFlow 时出现 "Read timed out"

python - 从 pisa/xhtml2pdf 的目录中排除第一页

python -/invoice/Flowable <PmlTable@0x1D09C899130 7 rows x 5 cols(tallest row 841)> with cell(0,0) 的布局错误

python - 将 GSL(或其他库)静态链接到共享库

django - 在 Django 1.7 中扩展用户配置文件