如何用 Flask 将 url 替换为 link 到 post 中的 url?
How to replace url with link to that url in post with Flask?
我如何使用 Python 和 Flask 在 post 中插入一个 link(如果有的话)。
例如,如果有人将 "google.com" 放入他们的 post 中,那么我如何才能将其设为 link?
如果您使用 jinja2 作为模板系统,您可以使用内置的 urlize 过滤器,它将某些文本中的所有 url 转换为 html link 标签:
{{ mytext|urlize(40, true) }}
links are shortened to 40 chars and defined with rel="nofollow"
它有许多有用的选项,您可以在文档中阅读:
http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-filters
如果您使用的是其他模板引擎,它们可能有类似的东西。
如果您想在客户端执行此操作,请在此处对所有选项进行很好的讨论:
How to replace plain URLs with links?
我如何使用 Python 和 Flask 在 post 中插入一个 link(如果有的话)。
例如,如果有人将 "google.com" 放入他们的 post 中,那么我如何才能将其设为 link?
如果您使用 jinja2 作为模板系统,您可以使用内置的 urlize 过滤器,它将某些文本中的所有 url 转换为 html link 标签:
{{ mytext|urlize(40, true) }}
links are shortened to 40 chars and defined with rel="nofollow"
它有许多有用的选项,您可以在文档中阅读:
http://jinja.pocoo.org/docs/dev/templates/#list-of-builtin-filters
如果您使用的是其他模板引擎,它们可能有类似的东西。
如果您想在客户端执行此操作,请在此处对所有选项进行很好的讨论:
How to replace plain URLs with links?