Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the filter built into the django template?

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shows you what the built-in filter of the django template is, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Filters built into django templates

1. Add

Add the passed parameter to the original value. This filter attempts to convert values and parameters into shapes and then add them. If the conversion to shaping fails, the values and parameters will be concatenated. If it is a string, it will be spliced into a string, and if it is a list, it will be spliced into a list. The example code is as follows:

{{value | add: "2"}}

If value is equal to 4, then the result will be 6. 5. If value is equal to an ordinary string, such as' abc', then the result will be abc2.

II. Cut

Removes all specified strings from the value. Similar to replace (args, ") in python. Example code:

{{value | cut: ""}}

III. Date

Formats a date into a string in the specified format. The example code is as follows:

# data

Context= {

"today": datetime.now ()

}

# template

{{value | date:'Y/m/d'}}

The result is 2019-12-30. Where Y represents a four-digit year, m represents a two-digit month, and d represents a two-digit day. There are other ways of formatting time.

Y: four-digit year

M: double-digit month

N: month, there is no 0 prefix before 1-9

D: double-digit days

J: God, there is no 0 prefix before 1-9.

G: hours, 12-hour format, 1-9 is not preceded by a 0 prefix

H: hours, 12-hour format, 1-9 preceded by a prefix of 0

G: hour, 24-hour format, 1-9 is not preceded by a 0 prefix

H: hours, 24-hour format, 1-9 with a prefix of 0

I: minutes, 1-9 with a prefix of 0

S: seconds, 1-9 prefixed with 0

The above content is what is the filter built into the django template, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report