Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#21303 closed New feature (wontfix)

Allow custom link text for urlize filter

Reported by: Danilo Bargen Owned by: nobody
Component: Template system Version: master
Severity: Normal Keywords: urlize, defaultfilters
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


My templates usually contain a lot of the following pattern:

<a href="{{ object.url }}">{{ }}</a>

It would be great if there were an optional link_text argument to the urlize filter:

{{ object.url| }}

I added a pull request for this here:

The pull request contains the implementation and tests. If you agree to include this in Django, I'll add a commit to this pull request that updates the documentation.

Change History (5)

comment:1 Changed 5 years ago by Tim Graham

While this works for your use case, I can imagine someone else may want to customize urlize and pass it arguments for a different purpose. For this reason, I think it's better for projects to have their own customized versions of urlize rather than for us to include a particular implementation in core. Will leave this open for a bit before making a "won't fix" call to see if anyone else wants to chime in.

comment:2 Changed 5 years ago by Danilo Bargen

Thanks for your comment.

I'm pretty sure that this is by far the most common use case for urlize customizations. But you might have a point there, because usually when creating URLs with a custom text, you don't want rel="nofollow" to be there.

Sometimes I miss Jinja's template filters with multiple arguments...

comment:3 Changed 5 years ago by Baptiste Mispelon

I'm also -1 on the idea.

The addition proposed here only makes sense when "urlizing" a single URL but that's not what urlize is designed for.
Its purpose is to find all the URLs inside a big chunk of text and convert them into clickable <a> tags.

I think that's reason enough to mark this as wontfix.
Please reopen this ticket if you have ideas on how to address the criticism raised here.


comment:4 Changed 5 years ago by Tim Graham

Resolution: wontfix
Status: newclosed

comment:5 Changed 5 years ago by Danilo Bargen

OK, valid point by bmispelon.

Note: See TracTickets for help on using tickets.
Back to Top