Django template Filter

Source: Internet
Author: User

In the previous section, I talked about the Django template syntax. You can use Django to display the data in the view on the page. This section mainly describes the Django template filter.

Django template character Truncation
Slice

Returns a slice of the list.

Example:

{Some_list | slice: ": 2 "}}

If some_list is ['A', 'B', 'C'], the output will be ['A', 'B'].
Remove HTML format from Django Template

Striptags

Strips all [x] HTML tags.

For example:

{Value | striptags }}

If value is"JoelIsSlug", The output will be" Joel is a slug ".

Template obtains the string length
Returns the length of the value. This works for both strings and lists.

For example:

{Value | length }}

If value is ['A', 'B', 'C', 'D'], the output will be 4.

If you want to learn more about the format and syntax of Django template. See the relevant documents.

We recommend that you read: About the configuration of the Django SQLite database and share your experiences with select_related ().

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.