Python webpy-url自动检测到超链接的字符串的某些部分

Python webpy-url自动检测到超链接的字符串的某些部分,python,web.py,Python,Web.py,我已经使用webpy创建了一个示例博客应用程序。我使用了一些代码here()来替换URL,但是当我呈现页面时,它不会显示超链接,而只是一个纯文本 在我的模板中: <p> <i>$datestr(post.posted_on) by $user</i><br/><br/> $urlify.formatstring(post.content) <p> $user的$datestr(post.p

我已经使用webpy创建了一个示例博客应用程序。我使用了一些代码here()来替换URL,但是当我呈现页面时,它不会显示超链接,而只是一个纯文本

在我的模板中:

    <p>
    <i>$datestr(post.posted_on) by $user</i><br/><br/>
    $urlify.formatstring(post.content)
    <p>

$user的$datestr(post.post_on)

$urlify.formatstring(post.content)
urlify.py

    def formatstring(self, value):
    pat1 = re.compile(r"(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)", re.IGNORECASE | re.DOTALL)

    pat2 = re.compile(r"(^|[\n ])(((www|ftp)\.[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)", re.IGNORECASE | re.DOTALL)
    value = pat1.sub(r'\1<a href="\2" target="_blank">\3</a>', value)
    value = pat2.sub(r'\1<a href="http://\2" target="_blank">\3</a>', value)

    return value
def formatstring(self,value):
pat1=re.compile(r“(^ |[\n])(([\w]+?:/[\w\\$%&.-]:=,?@\[\]+]*)(/[\w\\\\$%&-/.\:=,?@\[\]+]*)”,re.IGNORECASE | re.DOTALL)
pat2=re.compile(r“(^ |[\n])(((www.ftp)\.[\w\$%&.\-]:=,?@\[\]+]*)(/[\w\\\\$%&./.-]:=,?@\[\]+]),re.IGNORECASE | re.DOTALL)
value=pat1.sub(r'\1',value)
value=pat2.sub(r'\1',value)
返回值
示例文本:

这个网址会让你的生活变得轻松愉快!所以不要点击这个。一些url

页面呈现后的预期值应为:

这个网址会让你的生活变得轻松愉快!所以不要点击这个

但实际情况是:

这个网址会让你的生活变得轻松愉快!所以不要点击这个。一些url

Url未更改为超链接

编辑:在我的模板中:
将url视为超链接,而不是$content,它应该是$:content。

代码似乎没问题,您能否将传递给formatstring

方法的参数发布出来?

我编辑了我的文章,添加了一些细节,以使问题更清楚。我想您误解了代码的作用。它需要一个url,比如
http://www.example.com/foo/bar
并显示一个仅以文本形式显示域名的链接,因此在html中将
顺便说一句,从
http://www.example.com/foo/bar
)不是微不足道的你可以看看这个相关的问题是的,你说得对,我想我误解了函数。我已经解决了我的问题。而不是在我的模板:$context中,它应该是$:content以将url视为超链接。顺便说一句,谢谢你的时间。不要在标题中写“已解决”。