小编Akr*_*tar的帖子

Django - 使用 xhtml2pdf 将生成的 PDF 保存在模型中

我正在尝试使用 xhtml2pdf 应用程序保存生成的 PDF。我希望它将 pdf 保存到模型中。pdf 已完美创建,浏览器会下载该文件,但我不想下载,而是将其保存到模型中,在我的 models.py 中,我告诉它保存到媒体文件夹中的文件夹中。

模型.py:

class purchase(models.Model):
    purchase_id = models.AutoField(primary_key=True)
    transaction_date = models.DateTimeField()
    method_payment = models.CharField(max_length = 20)
    cmr_name = models.CharField(max_length = 60)
    cmr_address = models.CharField(max_length = 90)
    cmr_postcode = models.CharField(max_length = 10)
    cmr_tel = models.CharField(max_length = 14)
    cmr_email = models.CharField(max_length = 40)
    cmr_pod = models.FileField(upload_to='customers_id')
    cmr_signature = JSignatureField()
    receipt = models.FileField(upload_to='receipts', null=True, blank=True)
    added_by = models.CharField(max_length = 30)
    item_brand = models.CharField(max_length = 50)
    product = models.CharField(max_length = 100)
    model = models.CharField(max_length = 100)
    serial …
Run Code Online (Sandbox Code Playgroud)

python pdf django save xhtml2pdf

2
推荐指数
1
解决办法
2842
查看次数

标签 统计

django ×1

pdf ×1

python ×1

save ×1

xhtml2pdf ×1