Python/Django:使用xhtml2pdf将html呈现为pdf时获取AttributeError
你可以看到我犯的错误 我正在尝试使用Django从html模板呈现pdf。 当我摆弄它时,它在本地运行得相当好。 设法从中获取.pdf文件 现在我陷入了这个错误,声称uri没有属性编码。 有没有人在使用这个python包时出现过类似的错误?如果是这样,您是如何修复的Python/Django:使用xhtml2pdf将html呈现为pdf时获取AttributeError,python,django,pdf,attributeerror,xhtml2pdf,Python,Django,Pdf,Attributeerror,Xhtml2pdf,你可以看到我犯的错误 我正在尝试使用Django从html模板呈现pdf。 当我摆弄它时,它在本地运行得相当好。 设法从中获取.pdf文件 现在我陷入了这个错误,声称uri没有属性编码。 有没有人在使用这个python包时出现过类似的错误?如果是这样,您是如何修复的 from __future__ import print_function import easy_pdf from deliveries.models import Delivery from django.conf import
from __future__ import print_function
import easy_pdf
from deliveries.models import Delivery
from django.conf import settings
from easy_pdf.views import PDFTemplateView
import os
import sys
from django.core.wsgi import get_wsgi_application
from scripts import messages as msg
basename = os.path.splitext(os.path.basename(__file__))[0]
def run(*args, **kwargs):
if len(args) < 1 or args[0] is None:
print(msg.GeneralMessages.ERROR_DELIVERY_MISSING, file=sys.stderr)
sys.exit(1)
if not str(args[0]).isdigit():
logger.error(msg.GeneralMessages.ERROR_DELIVERY_INVALID)
sys.exit(1)
delivery = Delivery.get(args[0])
application = get_wsgi_application()
context = ''
view = ''
encoding = 'utf-8'
print(context)
view = easy_pdf.rendering.render_to_pdf('report.html', context)
if view:
f = open('report.pdf', 'wb')
f.write(view)
f.close()
print ('Report has been exported as .pdf')
if not settings.configured:
settings.configure(
DEBUG=True,
TIMEZONE="UTC",
INSTALLED_APPS=["easy_pdf", "django.contrib.staticfiles"],
TEMPLATE_DIRS=["../../deliveries/templates"],
ROOT_URLCONF=basename,
WSGI_APPLICATION="{}.application".format(basename),
STATIC_URL='/deliveries/static'
)