DjangoUnicodeDecodeError:' utf8'编解码器无法解码字节0x93 PDF文件未保存

时间:2017-04-19 06:10:15

标签: django encode

这是我在API中的一段代码:

    result = StringIO.StringIO()
    pdf_template = get_template(
        "submit_quotation.html").render(Context(ctx))

    result = StringIO.StringIO()
    pisa.pisaDocument(
        StringIO.StringIO(pdf_template), dest=result)
    attachment = result.getvalue()
    notification_template = NotificationTemplate.objects.get(
        notification_event='submitquote')
    print 'bro'
    Communication.objects.create(
        entity_id=obj.id,
        entity_name='quotation',
        entity_type=ContentType.objects.get(model='quotation'),
        # receivers=user_ids,
        subject=notification_template.subject,
        # to=user_ids[0],
        content=notification_template.content,
        communication_type=1,
        attachment=attachment
    )

在这里我正在创建一个PDF文件,并希望将其保存在模型中的FileField

模型是

 class Communication(Timestampable):
   attachment = models.FileField(
    upload_to=file_path,
    blank=True,
    null=True,
)

但是收到此错误

   DjangoUnicodeDecodeError: 'utf8' codec can't decode byte 0x93 in 
   position 10: invalid start byte. You passed in '%PDF-1.4\n%\x93......

0 个答案:

没有答案