簡體   English   中英

在 Django 模板中聲明自定義標簽過濾器

[英]Declare custom tag filter in Django template

我試圖用 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?

這是我的模板代碼:

{% original|get_customer_by_status:'CONFIRMATION_PENDING' as customer_pending_loan %}

然后我的自定義標簽過濾器:

@register.filter
def get_customer_by_status(queryset, status):
    print(queryset)
    print(status)

您可以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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM