Django有一个模板标签可以检测URL并将它们变成超链接吗? [英] Does Django have a template tag that can detect URLs and turn them into hyperlinks?

查看:167
本文介绍了Django有一个模板标签可以检测URL并将它们变成超链接吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当有人写帖子并复制并粘贴网址时,Django可以检测到它并将其渲染为超链接而不是纯文本吗?

When someone writes a post and copies and pastes a url in it, can Django detect it and render it as a hyperlink rather than plain text?

推荐答案

的Django具有 urlize模板过滤器它将自动检测URL和电子邮件地址,并将它们转换为适当的超链接。

Django has the urlize template filter which will automatically detect both URLs and email addresses and turn them into the appropriate hyperlinks.

那里的文档实际上有点薄,所以我建议你也阅读文档字符串在源为urlize功能了解详情。

The docs there are actually a little thin, so I recommend also reading the docstring in the source for the urlize function for more information.

这篇关于Django有一个模板标签可以检测URL并将它们变成超链接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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