一个简单的django应用程序,它会给你一个干净的html字段。

django-cleanhtmlfield的Python项目详细描述


#django cleanhtmlfield

[![图片](https://travis-ci.org/anexia-it/django-cleanhtmlfield.svg?branch=master)(https://travis ci.org/anexia it/django cleanhtmlfield)


django cleanhtmlfield是一个简单的django应用程序(支持django
1.8、1.11、2.0和2.1),它定义了一个自动删除潜在恶意内容的"htmlfield"。此应用程序应与python
2.7+和python3.4+一起使用。


窃取所有密码();
<;/script>;
<;p>;这是给你的!<;/p>;
```

`htmlfield`会将此筛选为

``html
<;h1>;你好朋友<;/h1>;
<;p>;这是给你的!<;/p>;
````

使用[pypi]中的"pip install"下载并安装(https://pypi.python.org/pypi/django cleanhtmlfield/):

```bash
pip install django cleanhtmlfield
````

2。在模型中创建一个字段"htmlfield(strip\u unsafe=true):

``python
from django.db import models
from django\u cleanhtmlfield.fields import htmlfield


some\content=htmlfield(strip\u unsafe=true)
```

>3。不要忘记为django
模型上的更改创建和运行迁移,例如:


``bash
python manage.py makemigrations
````

作为依赖项安装)。由于这是一个
django应用程序,它显然需要"django"(尽管我们希望它已经安装了)。

[alt text](docs/ckeditor-wysiwyg.png"ckeditor")



\如果您想使用'django ckeditor')

\…`)
-`acceptable_attributes`-包含所有允许的html
属性的元组(例如,`'alt','style','target','title',…`)
-`acceptable_styles`-包含所有允许的css样式的元组
(例如,`'background-color','border color','font size',…`)
-`remove_with_content`-包含潜在恶意的
html标记的元组,这些标记将被自动删除(例如,`'script',
'object',…`)


示例:

``python

acceptable_elements=(
'a','abbr','acronym','address','area,"aria label"、"b"、"big"、"blockquote"、"br"、"button"、"caption"、"center"、"cite"、"code"、"col"、"dd"、"del"、"dfn"、"dir"、"div"、"dl"、"dt"、"em"、"font"、"h1"、"h2"、"h3"、"h4"、"h5"、"h6"、"hr"、"i"、"img"、"ins"、"kbd"、"label"、"legend"、"li",'map'、'menu'、'ol'、
'p'、'pre'、'q'、's'、'samp'、'small'、'span'、'strike'、
'strong'、'sub'、'sup'、'table'、'tbody'、'td'、'tfoot'、'th'、
'thead'、'tr'、'tt'、'u'、'ul'、'var'、'iframe'、'section'、'article'、

"接受"、"accesskey"、"操作"、"对齐"、"alt"、"轴"、"边框"、"单元格填充"、"单元格间距"、"char"、"charoff"、"charset"、"checked"、"cite"、"class"、"clear"、"cols"、"colspan"、"color"、"compact"、"coords"、"d""ata mlang"、"数据公式"、"日期时间"、"目录"、"enctype"、"for"、"headers"、"height"、"ref"、"href lang"、"hspace"、"id"、"ismap"、"label"、"lang"、"longdesc"、"maxlength"、"method"、"multiple"、"name"、"noref"、"noshade"、"nowrap"、"prompt"、"rel"、"rev"、"rows",'rowspan'、'role'、'rules'、'scope'、'shape'、'size'、'style'、
'span'、'src'、'start'、'summary'、'tabindex'、'target'、'title'、'type'、
'usemap'、'valign'、'value'、'vspace'、'width'、

acceptable\u styles=(
'background color'、'background'、'backgro"背景位置"、"背景大小"、"背景重复"、"背景附件"、"背景原点"、"背景剪辑"、"字体系列"、"字体大小"、"字体粗细"、"字体样式"、"颜色"、"宽度"、"高度"、"最小宽度"、"宽度"、"最小高度"、"最大高度","行高","文本装饰","文本转换","文本对齐","边框","边框样式","边框宽度","边框顶部","边框底部","边框左侧","边框右侧","边框顶部样式","边框左侧样式","边框右侧样式","边框顶部宽度",
"边框底部宽度"、"边框左侧宽度"、"边框右侧宽度"、"边框颜色"、"边框顶部颜色"、"边框底部颜色"、"边框左侧颜色"、"边框间距"、"边框折叠"、"边框右侧颜色"、"边框半径"、"垂直对齐"、"清除",'float',
'margin','margin left','margin right','margin top','margin bottom',
'outline',
'padding','padding left','padding right','padding top','padding bottom',



```

rest_framework.serializer导入modelserializer

有效的HTML。')
}
default_empty_html=false
initial=false

def_uu init_u(self,**kwargs):
super(htmlfield,self)。
def to_u internal_u value(self,data):
return clean_html(data,





>modelserializer.serializer.serializer\u field映射[htmlfield]=reshtmlfield
``

《changelog


1.0.1






-将"受限"字段选项改为"自定义"字段选项,改为"自定义"字段选项,更新文档/自述





1.0









-初始释放

#license

[麻省理工学院许可证](license)

请对所有django和python版本运行
测试(例如,使用"tox"-请参见
"tox.ini"。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java邮件程序不再发送邮件了   java 2提交按钮不同的查询,   JavaFX2如何在javafx中制作全屏表单?   java ActionListener和ItemListener未正确实现   java通过Seam、RichFaces和PopupPanel传递参数   Google App Engine中的java XMPP和用于聊天应用程序的Android   javasocket异常:按下后退按钮后socket关闭   JavaSpring安全性阻止css、js文件加载到jsp页面上   java在另一个字符串中查找多个字符串   java是一种合适的方法,可以适应未来可完成的异常   引用的URL显示空值(Java、JSP)   我的子类构造函数中的java构造函数错误   Vaadin中的java样式与css   Java中指定目录的图像元数据   java如何在Android上对齐操作栏中的中心项