How do I add multiple arguments to my custom template filter in a django template?

前端 未结 9 467
时光说笑
时光说笑 2020-11-27 12:20

Here\'s my custom filter:

from django import template

register = template.Library()

@register.filter
def replace(value, cherche, remplacement):
    retur         


        
相关标签:
9条回答
  • 2020-11-27 12:54

    Heres a bad idea but works:

    {{ xml|input_by_xpath:"{'type':'radio','xpath':'//result/value'}" }}
    

    and

    @register.filter
    def input_by_xpath(device, args): 
        args = eval(args)
        ...
        result = "<input type=\"%s\" value=\"%s\" name=\"%s\"/>"%(args['type'],value,args['xpath'])
        return mark_safe(result)
    
    0 讨论(0)
  • 2020-11-27 13:02

    It's easy like this.

    @register.filter(name='one_more')
    def one_more(_1, _2):
        return _1, _2
    
    def your_filter(_1_2, _3)
        _1, _2 = _1_2
        print "now you have three arguments, enjoy"
    
    {{ _1|one_more:_2|your_filter:_3 }}
    
    0 讨论(0)
  • 2020-11-27 13:03

    You can just simply do this:

    {% assign find_total_issued = dailysalesreport | find: "TotalIssued":"13" %}
    
    public static List<object> Find(object collection, string column, string value)
    

    And it will reach the destination as the abstraction of the function is sjare.

    0 讨论(0)
提交回复
热议问题