2014-02-11 48 views
0

我已经下载在python比萨,它被安装在/usr/local/lib/python2.7/dist-packages 文件夹 我已经进口的,在我的项目作为进口ho.pisa作为比萨模块没有得到进口在Django

from django.http import HttpResponse 
from django.template.loader import render_to_string 
from django.template import RequestContext 
from django.conf import settings 
import ho.pisa as pisa 
import cStringIO as StringIO 
import cgi 
import os 
from unipath import Path 

PROJECT_ROOT=Path(__file__).ancestor(2) 


def html_to_pdf(request): 
    html = render_to_string('custodialrecon/html_to_pdf.html', { 'pagesize' : 'A4', }, context_instance=RequestContext(request)) 
    result = StringIO.StringIO() 
    pdf=pisa.pisaDocument(StringIO.StringIO(html.encode("UTF-8")),dest=result,link_callback=fetch_resources) 
    if not pdf.err: 
     return HttpResponse(result.getvalue(), mimetype='application/pdf') 
    return HttpResponse('Gremlins ate your pdf! %s' % cgi.escape(html)) 



def fetch_resources(uri, rel): 
    path = os.path.join(PROJECT_ROOT.child('assets'), uri.replace(PROJECT_ROOT.child('static'), "")) 
    return path 

当过我运行的项目,其显示<i>ImportError: No module named ho.pisa</i>

回答

0

您需要使用

from ho import pisa 

而不是

import ho.pisa as pisa