Django template system-Filter

Source: Internet
Author: User

Write down to save every time google

Filter, variable display form change

I. Format: lower case

{Name | lower }}

 

2. concatenation: Escape text to HTML first, and then convert each line to the <p> tag

{My_text | escape | linebreaks }}

 

3. filter parameters

Display the first 30 words
{Bio | truncatewords: "30 "}}

Format
{Pub_date | date: "F j, Y "}}

 

Filter list

{123 | add: "5"} adds a value to the value.

{"AB 'CD" | addslashes} is enclosed by an escape number in single quotes and is generally used for output to javascript.

{"Abcd" | capfirst} uppercase letters

{"Abcd" | center: "50"} output a string of the specified length, and set the value

{"123spam456spam789" | cut: "spam "}
{Value | date: "F j, Y"} format the date.

{Value | default: "(N/A)"} the specified value does not exist.

{Value | default_if_none: "(N/A)"} the value is None, and the specified value is used.

{List variable | dictsort: "Number"} is sorted from small to large.

{List variable | dictsortreversed: "Number "}

{% If 92 | divisibleby: "2" %} determines whether the specified number is divisible.

{String | escape} to html Entity

{21984124 | filesizeformat} is based on 1024 and calculates the maximum value. It retains 1 decimal place to increase readability.

{List | first} returns the first element of the list.

{"Ik23hr & jqwh" | fix_ampersands} & convert to & amp;

{13.414121241 | floatformat} retains one decimal number, which can be negative.

{13.414121241 | floatformat: "2"} Keep 2 decimal places

{23456 | get_digit: "1"} truncates one number at a specified position from the single digit.

{List | join: ","} connects to the list using the specified separator

{List | length} returned list count

{% If list | length_is: "3" %} whether the number of lists is a specified value

{"ABCD" | linebreaks} use <p> and <br/> to mark the package with a new line.

{"ABCD" | linebreaksbr} use a new line to mark the package with <br/>

{Variable | linenumbers} adds a row number to each row of the variable.

{"Abcd" | ljust: "50"} adds the string to the left in the specified width, and fills the other string with spaces.

{"ABCD" | lower} lower case

{% For I in "1abc1" | make_list %} ABCDE, {% endfor %} takes the number of characters of a string or number as a list

{"Abcdefghijklmnopqrstuvwxyz" | phone2numeric} converts the character into a corresponding number ??

The plural form of {list or number | pluralize} word. If the number of strings in the list is greater than 1, return s. Otherwise, return an empty string.

{List or number | pluralize: "es"} specifies es

{List or number | pluralize: "y, ies"} replace specified ies with y

{Object | pprint} displays the value of an object.

{List | random} returns a random entry in the list.

{String | removetags: "br p div"} Delete the html Tag specified in the string

{String | must ust: "50"} fill the string in the specified width to the right, and fill other strings with spaces.

{List | slice: ": 2"} slice

The {string | slugify} string contains a minus sign and an underscore. Other symbols are deleted and spaces are replaced by a minus sign.

{3 | stringformat: "02i"} string format, using the string format Syntax of Python

{"E <A> A </A> B <C> C </C> D" | striptags} removes the [X] HTML syntax tag

{Time variable | time: "P"} date time part format

{Datetime | timesince} How long has the specified date passed?
{Datetime | timesince: "other_datetime "}

{Datetime | timeuntil} specifies how much time has elapsed since the date, which is different from the previous two dates.

{Datetime | timeuntil: "other_datetime "}
{"Abdsadf" | title} uppercase letters

{"A B C D E F" | truncatewords: "3"} intercepts A specified number of words

{"<A> 1 <a> 1 <a> 1 </a> 22 <a> 1 </a>" | truncatewords_html: "2"} intercepts the specified number of html tags and completes

<Ul >{{ list | unordered_list }}</ul> multiple nested lists are unordered html lists.
{String | upper} all uppercase letters

<A href = "{link | urlencode}"> linkage </a> url Encoding

{String | urlize} changes URLs from plain text to clickable links. (No lab succeeded)
{String | urlizetrunc: "30"} is the same as above. It contains multiple characters. (No lab is successful)

{"B C D E F" | wordcount} Number of words

{"A B c d e f g h I j k" | wordwrap: "5"} inserts a carriage return for each specified number of characters

{Boolean | yesno: "Yes, No, Perhaps"} return strings for the three values, which are non-null, null, and None.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.