我有模型
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()
但我有一个错误:无法解析值
您需要将内容包装在 JSON blob 中,因此:
import json
product = Product.objects.get(id=…)
product.description = json.dumps(
{
'delta': {'ops': []},
'html': '<p> this is a test </p>',
}
)
product.save()