1

在这里你可以看到我得到的错误。

我正在尝试使用 Django 从 html 模板呈现 pdf。当我摆弄它时,这在本地工作得很好。设法从中获取 .pdf 文件。

现在我被这个错误困住了,声称 uri 没有属性编码。有没有人在使用这个 python 包时遇到过类似的错误?如果是这样,您是如何解决的?

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'
    )
4

0 回答 0