How to flexibly adjust the truncation length when using `urlizetrunc`, for example, based on the device type?

Calendar 👁️ 67

How to ensure that information is presented in a **way to every visitor on the corporate website, which is crucial for improving user experience and the effectiveness of content marketing.Especially when the website content contains a large number of external links or long URLs, how to cleverly handle the display of these links so that they are both beautiful and complete, and can also adapt to the screen sizes of different devices, has become a task that requires fine management.provided by AnQiCMS (AnQiCMS)urlizetruncThe filter is the tool to solve this problem.

urlizetruncThe basics of link beautification:

AnQi CMS uses a template engine syntax similar to Django, providing rich built-in tags and filters to make template development and content display flexible and efficient. Among them,urlizetruncThe filter is used to automatically identify URLs or email addresses in text and convert them into clickable links<a>Label and automatically addrel="nofollow"This property is very beneficial for SEO optimization and external link management.

urlizetruncThe distinctive feature is that it allows you to specify a truncation length. When the displayed text of the URL exceeds this length, it automatically adds an ellipsis at the end....Truncate it to avoid breaking the layout or affecting the reading experience of the URL.

For example, if there is a very long URL text in the template:

<p>访问我们的官方网站:{{ "http://www.example.com/products/category/detail/very-long-product-name-with-many-keywords"|urlizetrunc:30|safe }} 获取更多信息。</p>

This code will display it as:

`html

Visit our official website:

Related articles

The `urlize` filter does it attempt to verify the validity or accessibility of the URL?

In AnQiCMS (AnQiCMS) content operation, we often need to automatically convert text links or email addresses into clickable hyperlinks in the article text.To achieve this goal, the `urlize` filter is a very convenient and commonly used tool.However, many users might be curious whether this `urlize` filter, while converting links, would also try to verify the validity or accessibility of these URLs?In short, the answer is: **No**. `urlize` filter is in AnQiCMS

2025-11-09

How to make `urlize` output HTML links correctly without using the `safe` filter?

The AnQiCMS template system provides a solid foundation for content operations with its powerful functions and flexible customization.In daily content display, we often encounter the need to automatically convert URLs in plain text to clickable HTML links.The `urlize` filter is designed for this purpose, it can intelligently recognize URLs or email addresses in text and wrap them in `<a>` tags.However, a common practice when using the `urlize` filter is to pair it with the `|safe` filter

2025-11-09

Does the `urlize` filter-generated link include the `title` or `alt` attributes of the original URL?

In Anqi CMS templates, the `urlize` filter can effectively convert URLs in text content into clickable HTML links.For many users, while using this convenient feature, they are also concerned about whether the generated link will automatically include `title` or `alt` attributes to enhance user experience or optimize SEO.

2025-11-09

Is there a global option in the AnQiCMS background settings that affects the behavior of `urlize` and `urlizetrunc`?

When using AnQiCMS to manage website content, we often encounter the need to automatically convert URLs or email addresses in text to clickable links.`urlize` and `urlizetrunc` are powerful tools to implement this function.They can not only automatically identify links in text but also automatically add the `rel="nofollow"` attribute to links after conversion, which is very practical for SEO optimization.However, many friends may be curious when using these filters

2025-11-09

Does the `urlize` filter support custom attributes of the generated `<a>` tag, such as `data-*`?

AnQiCMS (AnQiCMS) plays an important role in website construction and content operation with its efficient and flexible content management features.In daily content display and template development, we often take advantage of the built-in various filters to conveniently handle data.Among them, the `urlize` filter is a very practical tool that can automatically identify links in text and convert them into clickable HTML `<a>` tags.However, does the `urlize` filter support adding custom properties like `data-*` to these automatically generated `<a>` tags

2025-11-09

If the text contains duplicate URLs, will the `urlize` filter generate the same `<a>` tags repeatedly?

In daily website content operation, we often need to include various links in articles or pages, whether they point to other pages within the site or refer to external resources.AnQiCMS (AnQiCMS) provides many convenient tools to simplify this process, among which the `urlize` filter is a very practical feature.It can automatically identify URLs or email addresses in text and convert them into clickable HTML links.However, when using this convenient feature, a common question may arise in one's mind: if our text contains multiple identical URLs

2025-11-09

Does the `urlize` filter correctly encode URLs containing special characters (such as `&`, `=`)?

When using Anqi CMS for content operations, we often need to reference external links or email addresses in articles.To make these links clickable while also ensuring the page's neatness and security, Anq CMS has built-in many practical template filters, among which the `urlize` filter is a good helper for dealing with such needs.

2025-11-09

How to ensure that the `urlize` filter only acts on text and does not affect the `src` or `href` attributes of images or other HTML elements?

In Anqi CMS template development, the `urlize` filter is a very practical tool that can intelligently identify URLs or email addresses in text and automatically convert them into clickable hyperlinks.This brings great convenience to us in processing user input or pure text content obtained from other sources, making the information more friendly and interactive when displayed on the front end.

2025-11-09