Django filter and date formatting Parameters

Source: Internet
Author: User

Reprinted: http://blog.csdn.net/xyp84/article/details/7945094

 

Django1.4

When the HTML page reads the datetimefield field from the database, the displayed time format is different from the format stored in the database. For example, the database field content is 16:00:00, but the page displays Aug. 26,201 2, 4 p. m.

To make the page consistent with that displayed in the database, you need to add <TD >{{ dayrecord. p_time | Date: "Y-m-d h: I: s" }}</TD> similar filter. Refresh the page to display it normally.

 

Filter related:

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.

 

Date Format parameters:

A' a. m. 'or 'p. M.' (note that it is slightly different from the PHP output. It includes a period (Django Extension). 'A. M .'
A 'am' or 'pm '. 'am'
B is not implemented.
D The day of each month, with the leading zeros '01' to '31'
D The day of the week, a 3-character string. 'fri'
F time, 12-hour and minutes. If the number of minutes is zero, it is not displayed. (Django Extension). '1', '1: 30'
Month F, long text format. 'january'
G hour, in 12-hour format, without leading zeros '1' to '12'
G hour, in 24-hour format, without leading zeros '0' to '23'
H hour, in 12-hour format, with leading zeros '01' to '12'
H-hour, in 24-hour format, with leading zeros '00' to '23'
I minute. '00' to '59'
I not implemented
J. The day of each month, with no leading zeros '1' to '31'
L day of each week, long text format. 'Friday'
L leap year. True or false
M number indicates the month, with a leading zero. '01 'to '12'
M month, 3-letter short text format. 'Jan'
N indicates the month with no leading zeros '1' to '12'
N publication-style month abbreviations (Django extensions) 'Jan. ', 'feb.', 'march', 'may'
The time difference between O and Greenwich Mean (hours) '+ 0200'
P 12-hour minutes and 'a. m. '/' p. m. 'If the number of minutes is zero, it is not displayed. use a string to represent special time points, such as 'midnight 'and 'noon' (Django extension) '1. m. ', '1: 30 p. m. ', 'midnight', 'noon', '12: 30 p. m.'
R RFC 822 format date. 'thu, 21 Dec 2000 16:01:07 + 123'
S seconds. A number with a leading zero indicates '00' to '59'
The suffix of the S English ordinal number, which is used for the day of a month, with 2 Characters: 'st', 'nd', 'RD 'or 'th'
T Total number of days in a given month. 28 to 31
T local time zone. 'Est ', 'mdt'
U not implemented
W the day of the week without the leading zero digit '0' (Sunday) to '6' (Saturday)
W ISO-8601 the number of weeks a year, starting from Monday 1, 23
Y year, two digits represent '99'
Y year, 4 digits for '20140901'
The day of the year in Z. 0 to 365
The Time Zone offset of Z in seconds. This offset is always negative for the Western UTC time zone, while the eastern UTC time zone is always positive-43200 to 43200

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.