在python中转出html? [英] Escape html in python?

查看:117
本文介绍了在python中转出html?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个< img src = __ string __> 字符串可能包含,我该怎么办才能逃脱? >

示例:

  __ string__ = test.jpg 
< img src =test.jpg>

无效。

解决方案

如果您的转义值可能包含引号,最好使用 quoteattr 方法: http://docs.python.org /library/xml.sax.utils.html#module-xml.sax.saxutils



这是在cgi.escape( )方法。


i have a <img src=__string__> but string might contain ", what should I do to escape it?

Example:

__string__ = test".jpg
<img src="test".jpg">

doesn't work.

解决方案

If your value being escaped might contain quotes, the best thing is to use the quoteattr method: http://docs.python.org/library/xml.sax.utils.html#module-xml.sax.saxutils

This is referenced right beneath the docs on the cgi.escape() method.

这篇关于在python中转出html?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆