django app中创建python package
templatetags
templatetags中创建自己的自定义模版py文件
模版详细
from django import template
from django.utils.html import format_html
register = template.Library()
@register.filter
def myupper(value):
return value.upper()
@register.simple_tag
def page_guess(current_page, loop_num):
offset = abs(current_page - loop_num)
if offset < 3:
if current_page == loop_num:
page_element = '<li class="active"><a href="?page=%s">%s</a></li>' % (loop_num, loop_num)
else:
page_element = '<li class=""><a href="?page=%s">%s</a></li>' % (loop_num, loop_num)
return format_html(page_element)
else:
return ''
对应模版中应load所创建的py文件名称
{#添加自定义模版函数#}
{% load stucrm_extras %}