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.urlizedjango.template.defaultfilters.urlize的代码复制到您的项目中,或者复制到单独的应用程序中,并使用新的定义.

Django相关问答推荐

在Django的反向函数中添加动态URL

Django Form初始值不在呈现上起作用

在AWS s3中获取项目的URL

获取PyCharm中继承方法的未解析属性引用

测试 - 两个类共享相同的登录代码,但它只能在一个类中工作

如何使用具有某些权限的 Django 组的转储数据和加载数据?

如何将数据库中的 None 序列化为空对象?

如何在 Django 模板中的计数器上进行 for 循环中断?

在 Django 网站上找不到页面 404?

在 Django 管理员中嵌套内联?

如何在 django-rest-framework 中为 API 使用 TokenAuthentication

CherryPy 与 Django

Django:如何使用动态(非模型)数据预填充 FormView?

有 Django List View 模型排序吗?

Django JavaScript 文件

如何在 Django 1.9 中删除 DB (sqlite3) 以从头开始?

如何在 Django/Python 中减go 两个日期?

Django 应用程序运行良好,但收到 TEMPLATE_* 警告消息

使用 request.user 的 Django 和中间件始终是匿名的

Django Admin - save_model 方法 - 如何检测字段是否已更改?