How it works...

We can use the humanize_url filter in any template, as follows:

{% load utility_tags %}
<a href="{{ object.website }}" target="_blank">
    {{ object.website|humanize_url:40 }}
</a>

The filter uses regular expressions to remove the leading protocol and trailing slash, shortens the URL to the given amount of letters, and adds an ellipsis to the end after truncating it if the full URL doesn't fit the specified letter count. For example, for the URL https://docs.djangoproject.com/en/2.1/ref/request-response/, the 40-character humanized version would be docs.djangoproject.com/en/2.1/ref/reque...

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.200.180