【问题标题】:how to remove html encodings from a string in django [duplicate]如何从django中的字符串中删除html编码[重复]
【发布时间】:2021-06-05 18:10:20
【问题描述】:

我使用了 strip_tags 函数。它删除了"<p>, <b>" 等标签,但"  “" 和其他html 编码之类的东西仍然存在。如何删除它们?

【问题讨论】:

标签: python django django-views django-templates


【解决方案1】:

将字符串传递给“取消引用”函数

from urllib.parse import unquote
s = unquote(s)

【讨论】:

  • 参见 html.unescape
  • @mkalioby,它不起作用
  • @JustinEzequiel,太棒了!谢谢:D
  • 此函数解码 URL 请求转义(您在 URL 中找到的那些,格式为 %xx - 就像空格字符的“%20”),而不是格式为 &... 的 HTML 转义.见documentation
  • 感谢您的提示和解释
猜你喜欢
  • 2012-02-14
  • 2011-05-03
  • 2012-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多