Django Filter, date formatting parameters

Source: Internet
Author: User

django1.4

When the HTML page reads the Datetimefield field from the database, the displayed time format is inconsistent with the format stored in the database, for example, the database field content is 2012-08-26 16:00:00, but the page shows an. 4 p.m.,

In order for the page and the database to display consistent, need to be in the page format time, need to add <td>{{dayrecord.p_time|date: "y-m-d h:i:s"}}</td> a similar filter. Refresh the page to display normally.

Filter Related:

First, form: lowercase
{{name | lower}}

Second, concatenation: First escape the text to HTML, and then convert each line to the <p> tag
{{My_text|escape|linebreaks}}

Three, the parameters of the filter
Show Top 30 characters
{{bio | truncatewords: ' 30 '}}

Formatting
{{pub_date | date: ' F J, Y '}}

Filter List
{{ 123|add: ' 5 '  }}  add a value to value
{{  "AB ' CD" |addslashes }}  single quote with escape number, Typically used for output to JavaScript
{{  "ABCD" |capfirst }}  first letter uppercase
{{  "ABCD" |center: " }}  Outputs a string of the specified length and puts the value pair in
{{  "123spam456spam789" |cut: "spam"  }}  Find delete the specified string
{{ value|date: "F  j, y " }}  formatted date
{ value|default:" (N/a) " }}  value does not exist, use the specified value
{{ value| Default_if_none: "(N/a)"  }}  value is none, use the specified value
{{  list variable |dictsort: "Number"  }}  sort from small to large
{{   List variable |dictsortreversed: "Number"  }}  sort from large to small
{% if 92|divisibleby: "2"  %}  Determines whether the specified number is divisible by


{{String|escape}} converted to HTML entity
{{21984124|filesizeformat}} is based on 1024, calculates the maximum value, retains 1 decimal places, and increases readability
{{List|first}} returns the first element of the list
{{"Ik23hr&jqwh" |fix_ampersands} & Switch to &amp;
{{13.414121241|floatformat}} retains 1 decimal places, can be negative, several forms
{{13.414121241|floatformat: ' 2 '}} reserved 2 decimal places
{{23456 |get_digit: ' 1 '}} intercepts 1 digits at the specified position starting at single digit


{{list|join: ","}} to connect the list with the specified delimiter
{{List|length}} returns the number of lists
{% If list |length_is: "3"%} list number Specify value
{"ABCD" |linebreaks}} marks the parcel with a new line with <p>, <br/>
{"ABCD" |LINEBREAKSBR}} marks the parcel with a new line with <br/>
{{variable |linenumbers}} is a row number for each row in the variable
{"ABCD" |ljust: "50"}} The string is left in the specified width, and the other is filled with spaces


{"ABCD" |lower}} lowercase
{% for I in "1ABC1" |make_list%} abcde,{% endfor%} The number of characters in a string or number as a list
{{"abcdefghijklmnopqrstuvwxyz" |phone2numeric}} to convert a character to a corresponding number??
{{list or number |pluralize}} The plural form of the word, such as the number of list strings greater than 1, returns s, otherwise returns an empty string


{{List or number |pluralize: ' Es '}} specify ES
{{List or number |pluralize: ' Y,ies '}} specify ies to replace with Y
{{Object|pprint}} displays the value of an object
{{list |random}} returns a random item of the list
{{string|removetags: "br P div"}} delete the specified HTML tag in the string
{{string|rjust: ' 50 '}} put the string in the specified width to the right, and the other with a space padding


{{List |slice: ': 2 '}} Slice
{{string|slugify}} string left minus and underscore, other symbols deleted, spaces replaced with minus sign
{{3|stringformat: ' 02i '}} string format, using Python's string format syntax
{{"E<a>a</a>b<c>c</c>d" |striptags}} Stripped [x]html syntax tag
{{Time variable |time: ' P '}} Date Time part format
{{datetime|timesince}} How long has it been in the past given the date
{{datetime|timesince: ' Other_datetime '}} How much time has elapsed in two days


{{Datetime|timeuntil}} How much time has elapsed from the given date to the present, the difference from the above is the position before and after the 2nd period.
{{datetime|timeuntil: ' Other_datetime '}} How much time has elapsed in two days
{{"ABDSADF" |title}} Capitalize first letter
{{"A B C D E F" |truncatewords: "3"}} intercepts a specified number of words
{"<a>1<a>1<a>1</a></a></a>22<a>1</a>" |truncatewords_html: "2"} } intercepts the specified number of HTML tags and complements the complete
<ul>{{list|unordered_list}}</ul> Multiple nested lists are displayed as an unordered list of HTML


{{String|upper}} all uppercase
<a href= "{{link|urlencode}}" >linkage</a> URL encoding
{{string|urlize}} changes URLs from plain text to clickable links. (No experimental success)
{{string|urlizetrunc: ' 30 '}}, more than one number of characters intercepted. (also no experimental success)


{{"B C D E F" |wordcount}} Word number
{{"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 '}} returns a string of three values, corresponding to non-null, NULL, None

Date formatting parameters:

A ' a.m. ' or ' p.m. ' (note that it is slightly different from the output of PHP.) It includes a period (Django extension). ' a.m. '
A ' AM ' or ' PM '. ' AM '
B is not implemented.
D The day of the month, with a leading 0 ' to ' 31 '
D the first day of the week, a 3-letter string. ' Fri '
F time, 12-hour hours and minutes, if the number of minutes is zero, is not displayed. (Django extension). ' 1 ', ' 1:30 '
F month, long text format. ' January '
G-hour, 12-hour system without leading 0 ' 1 ' to ' 12 '
G-hour, 24-hour system without leading 0 ' 0 ' to ' 23 '
H-hour, 12-hour system with leading 0 ' to ' 12 '
H-hour, 24-hour, with leading 0 ' xx ' to ' 23 '
I minute. ' xx ' to ' 59 '
I was not implemented
J Day of the month, no leading 0 ' 1 ' to ' 31 '
L Day of the week, long text format. ' Friday '
L whether a leap year. True or False
The month represented by the m number, with a leading 0. ' 12 '
M month, 3 letter short text format. ' Jan '
n number of months, without leading 0 ' 1 ' to ' 12 '
N published-style month abbreviation (Django extension) ' Jan ', ' Feb ', ' March ', ' may '
O time difference from Greenwich (in hours) ' +0200 '
P 12 hour minutes and ' a.m. '/' p.m. ' Minutes if zero is not displayed. Use strings to represent special points of time, such as ' Midnight ' and ' Noon ' (Django Extensions) ' 1 a.m. ', ' Midnight ', ' noon ', ' 12:30pm '.
The date in the R RFC 822 format. ' Thu, Dec 2000 16:01:07+0200 '
s seconds, with a leading zero number indicating ' xx ' to ' 59 '
S English ordinal suffix, used for the first day of one months, 2 characters ' st ', ' nd ', ' rd ' or ' th '
T total number of days for a given month. 31 to
T-Machine area. ' EST ', ' MDT '
U not implemented
W The first day of the week, no leading zeros of the number ' 0 ' (Sunday) to ' 6 ' (Saturday)
W ISO-8601 Number of weeks of the year, week starting from Monday 1, 23
Y year, 2 digits means ' 99 '
Y year, 4 digits means ' 1999 '
Z The day of the year. 0 to 365
Z The time zone offset in seconds. This offset is always negative for the UTC West time zone, and is always positive for UTC Eastern Time zone -43200 to 43200

Django Filter, date formatting parameters

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.