在django扩展urlize [英] extending urlize in django

查看:154
本文介绍了在django扩展urlize的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

django.utils.html的urlize函数将url转换为可点击的链接。我的问题是我想在< href ..>中添加一个target =_ blank,以便我在一个新的选项卡中打开此链接。有什么办法可以扩展urlize函数来接收额外的参数吗?或者我应该使用正则表达式做一个自定义过滤器来做这些东西?这是否有效?

the urlize function from django.utils.html converts urls to clickable links. My problem is that I want to append a target="_blank" into the "< href..>", so that I open this link in a new tab. Is there any way that I can extend the urlize function to receive an extra argument? or should I make a custom filter using regexes to do this stuff? Is this efficient?

推荐答案

内置的 urlize()这样做。由于Django的许可,您可以复制代码 django.utils.html.urlize django.template.defaultfilters.urlize 进入您的项目或单独的应用程序,并使用新的定义。

There is no capability in the built-in urlize() to do this. Due to Django's license you can copy the code of django.utils.html.urlize and django.template.defaultfilters.urlize into your project or into a separate app and use the new definitions instead.

这篇关于在django扩展urlize的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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