extending urlize in django

后端 未结 4 1203
生来不讨喜
生来不讨喜 2020-12-25 12:29

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 ope

4条回答
  •  长情又很酷
    2020-12-25 12:47

    You shouldn't add target="_blank" to your links, it's deprecated. Users should decide themselves if where they want to open a link.

    You can still open the link with unobtrusive JavaScript like so (using jQuery):

    $('.container a').click(function(e){e.preventDefault();window.open(this.href);});
    

    That said, you could write your own filter, but you'd have to copy a lot of code from django.utils.html.urlize, not really DRY.

提交回复
热议问题