Django - 将 html 数据保存到 quillfield 中

问题描述 投票:0回答:1

我有模型

 class Product(models.Model): 
description = QuillField(null=True, blank=True)

在 django 视图中如何保存 html 数据?

product = Product.objects.get(id=...) 
product.description = '<p> this is a test </p>'
product.save()

但我有一个错误:无法解析值

django quill
1个回答
0
投票

您需要将内容包装在 JSON blob 中,因此:

import json

product = Product.objects.get(id=…)
product.description = json.dumps(
    {
        'delta': {'ops': []},
        'html': '<p> this is a test </p>',
    }
)
product.save()
© www.soinside.com 2019 - 2024. All rights reserved.