[英]Declare custom tag filter in Django template
Am trying to declare a custom function with 2 parameters but it isn't working as expected , am getting this error :我试图用 2 个参数声明一个自定义函数,但它没有按预期工作,我收到此错误:
Invalid block tag on line 4: 'original|get_customer_by_status:'CONFIRMATION_PENDING'', expected 'endblock'. Did you forget to register or load this tag?
This is my template code :这是我的模板代码:
{% original|get_customer_by_status:'CONFIRMATION_PENDING' as customer_pending_loan %}
Then my custom tag filter :然后我的自定义标签过滤器:
@register.filter
def get_customer_by_status(queryset, status):
print(queryset)
print(status)
You can use with
template tag:您可以
with
模板标签with
使用:
{% with customer_pending_loan=original|get_customer_by_status:'CONFIRMATION_PENDING' %}
your code here where you need to use customer_pending_load variable
{% endwith %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.