python - Django - string from variable inside template tag -
i can't figure out how send multiple arguments custom template filter.
the problem use template variables arguments.
custom template filter
@register.filter def is_scheduled(product_id,dayhour): day,hour = dayhour.split(',') return product.objects.get(id=product_id).is_scheduled(day,hour) normal use
{% if product.id|is_scheduled:"7,22" %}...{% endif %} the line above work correctly put 2 arguments - 7 , 22 filter (tested - works). problem want put variables instead of plain text/string argument.
in template:
{% day=forloop.counter|add:"-2" hour=forloop.parentloop.counter|add:"-2" %} now, want use {{ day }} , {{ hour }} arguments.
i tried example:
{% if product.id|is_scheduled:"{{ day }},{{ hour }}" %}...{% endif %} but raises:
exception value: invalid literal int() base 10: '{{ day }}'
do have ideas?
you don't need {{}} when you're inside {% %}. use names directly in tag , use string concat template syntax add.
in case day , hour strings, type conversion string required before concating strings:
{% day|stringformat:"s" sday hour|stringformat:"s" shour %} {% sday|add:","|add:shour arg %} {% if product.id|is_scheduled:arg %}...{% endif %} {% endwith %} {% endwith %}
Comments
Post a Comment