简体   繁体   English

Django> xhtml2pdf>使它起作用吗?

[英]Django > xhtml2pdf > Getting it to work?

I'm having problems understanding how I should install xhtml2pdf. 我在理解如何安装xhtml2pdf时遇到问题。 I have followed the instructions at Chris Glass's site and have a virtual environment setup and have run unit tests. 我已经按照Chris Glass网站上的说明进行操作,并进行了虚拟环境设置并进行了单元测试。 When I insert the following at the top of my views.py file: 当我在views.py文件顶部插入以下内容时:

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

I get an error saying No module named ho.pisa (which I expected) . 我收到一条错误消息,提示No module named ho.pisa (我期望) How do I get django or even the python command line import this module (because I have tried importing the module in the command line with the same level of success) . 我如何获得django甚至python命令行导入此模块(因为我尝试在命令行中以相同的成功级别导入该模块)

EDIT 编辑

Why do I need a virtual enviroment. 为什么需要虚拟环境。 Can't I just install xhtml2pdf as a package and import it normally or will I break some Django/python thing? 我不能仅将xhtml2pdf作为软件包安装并正常导入,还是会破坏Django / python的内容?

EDIT 编辑

I have also run django from inside the xhtml2pdf virtual enviroment > (xhtml2pdfenv)person@person-laptop:~/Software/django$ ./manage.py runserver and still it refuses to import xhtm2pdf 我还从xhtml2pdf虚拟环境内部运行django> (xhtml2pdfenv)person@person-laptop:~/Software/django$ ./manage.py runserver ,但它仍然拒绝导入xhtm2pdf

I just tried installing xhtml2pdf using pip, not the package. 我只是尝试使用pip而非软件包安装xhtml2pdf。

The pisa module was in xhtml2pdf , not ho pisa模块在xhtml2pdf ,而不是ho

>>> import xhtml2pdf.pisa as pisa

您可以通过以下行安装比萨:

easy_install pisa

Right. 对。 I got it to work by doing the following after step 5 of the development enviroment at Chris Glass's site: 在Chris Glass网站的开发环境的 第5步之后,通过执行以下操作使它起作用:

$ python setup.py install
# navigate to you django project
$ cd ../django
$ ./manage.py runserver

The import line from xhtml2pdf import pisa in views.py does not raise any errors any more from xhtml2pdf import pisa views.py中的from xhtml2pdf import pisa的导入行不再引发任何错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM