将未标记的链接包装到<;a>;使用Python或Django标记

将未标记的链接包装到<;a>;使用Python或Django标记,python,django,Python,Django,使用Python,如何获取具有以下未格式化链接的字符串: str = "<p>Here's some safe html with a link to somewhere: \ https://google.ca but there might also be some images <img \ src='https://commons.wikimedia.org/wiki/File:Man-in-circle_icon.svg' /> \ and other link

使用Python,如何获取具有以下未格式化链接的字符串:

str = "<p>Here's some safe html with a link to somewhere: \
https://google.ca but there might also be some images <img \
src='https://commons.wikimedia.org/wiki/File:Man-in-circle_icon.svg' /> \
and other linky looking things</p>"
str = "<p>Here's some safe html with a link to somewhere: \
<a href='https://google.ca' target='_blank'>https://google.ca</a> but there might also be some images <img \
src='https://commons.wikimedia.org/wiki/File:Man-in-circle_icon.svg' /> \
and other linky looking things</p>"
str=“以下是一些安全的html,其中包含指向某个地方的链接:\
https://google.ca 但也可能有一些图像\
和其他看起来像链接的东西

并将其包装在如下标记中:

str = "<p>Here's some safe html with a link to somewhere: \
https://google.ca but there might also be some images <img \
src='https://commons.wikimedia.org/wiki/File:Man-in-circle_icon.svg' /> \
and other linky looking things</p>"
str = "<p>Here's some safe html with a link to somewhere: \
<a href='https://google.ca' target='_blank'>https://google.ca</a> but there might also be some images <img \
src='https://commons.wikimedia.org/wiki/File:Man-in-circle_icon.svg' /> \
and other linky looking things</p>"
str=“以下是一些安全的html,其中包含指向某个地方的链接:\
但也可能有一些图像\
和其他看起来像链接的东西


Django的模板过滤器正好用于此目的。

“如果将urlize应用于已包含HTML标记的文本,则无法按预期工作。仅将此过滤器应用于纯文本。”因此,我的示例无法使用此过滤器。