django - Django 表单已清理
问题描述
当我点击保存按钮时,我的表单也会保存 html 元素。我的表格如下所示:
class ProductPropertyForm(forms.ModelForm):
class Meta:
model = ProductProperty
fields = ('name', )
例如,如果我的文本是“我的输入文本”。表单将其保存在数据库中:从保存的数据<p>My input text</p>
中排除 html 元素的解决方案是什么?p
解决方案
您可以使用这样的clean
方法返回清理后的数据:
class ProductPropertyForm(forms.ModelForm):
class Meta:
model = ProductProperty
fields = ('name', )
def clean_name(self):
cleaned_name = self.cleaned_data['name']
return cleaned_name
推荐阅读
- javascript - 如何循环
我有一个 html 源代码作为变量,并希望遍历每个 li 并提取所需的数据。我尝试使用 $(strVar).find("li").each(function(){alert($(this).text()); }); 但我无法获得介于两者之间的数据!你们能告诉我这是怎么做到的吗?谢谢
Data to ex
- vuex - 为什么第一次登录后没有数据?
- python-3.x - 如何成功导入硒
- php - 使用本地 AD 单点登录
- c# - 在 .NET Core 3 中反序列化使用 .NET Framework 创建的二进制文件时出现问题
- r - 计算一天内两个 hh:mm 变量之间的时间差
- javascript - 如何编写函数将窗口加载延迟 3 秒?
- python - FacetPlot/CatPlot (seaborn) - 如何改变柱的位置?
- css - 传递包含值的文件以在命令行中修改较少的变量
- android - VideoView seekTo 0 而不是特定位置