Custom Functions for Django templates

Source: Internet
Author: User

-Custom functions
Simple_tag
A. Create templatetags directory under App
B. Any xxoo.py file
C. Creating a Template object register
D.

__author__ = ' Administrator '
From Django Import Template
From django.utils.safestring import Mark_safe

Register = template. Library ()
@register. Simple_tag

def func (A1,a2,a3 ...)
Return "ASDFASD"
E. Register app in Settings
F. Top {% load Xxoo%}
G. {% function name arg1 arg2%}
Disadvantages:
cannot be used as an if condition

Advantages:
Parameter any

Filter
A. Create templatetags directory under App
B. Any xxoo.py file
C. Creating a Template object register
D.
@register. Filter
def func (A1,A2)
Return "ASDFASD"
E. Register app in Settings
F. Top {% load Xxoo%}
G. {{parameter 1| function name: "Parameter two, parameter three"}} {{parameter 1| function name: number}}
Disadvantages:
Up to two parameters, cannot add a space
Advantages:
Can be used as an if condition

Custom Functions for Django templates

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.