模块没有在django中导入

时间:2014-02-11 05:50:04

标签: django-models python-import

我已经在python中下载了pisa,它已经安装在/usr/local/lib/python2.7/dist-packages中 夹 我已经在我的项目中导入了导入ho.pisa作为pisa

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>

1 个答案:

答案 0 :(得分:0)

您需要使用

from ho import pisa

而不是

import ho.pisa as pisa