Home > OS >  Django-is it possible to use template filters inside "with"?
Django-is it possible to use template filters inside "with"?

Time:12-13

I have a template filter called "get_data_id" that returns a value; I want to use that value as an argument for another filter called "get_data":

{% with variable_v= "x|get_data_id"  %}
    <p> {{ variable_v|get_data }} </p>
{% endwith %}

But django returns:

'with' expected at least one variable assignment

Is it possible to use template filters in "with clause" ?

CodePudding user response:

you have a wrong Synaxis. In your case:

{% with variable_v=x|get_data_id %}
    <p> {{ variable_v|get_data }} </p>
{% endwith %}

Bug is - use space_letter around "=" in with clause, next bug is - use string "x|get_data_id" instead of variable and filter x|get_data_id.

  • Related