Declare Variables on Django Templates Django.How

Author avatar wrote on 07/06/2022

Django

Using with

{% with name="Kim" %}
    
Hello {{name}}!
{% endwith %}

With and =

{% with total=business.employees.count %}
    {{ total }} employee{{ total|pluralize }}
{% endwith %}

With and as

{% with business.employees.count as total %}
    {{ total }} employee{{ total|pluralize }}
{% endwith %}

Update variale with JS only

Django & JS

from django to JS

Or

{{ variable|json_script:'name' }}
var js_variable = JSON.parse(document.getElementById('name').textContent);

From input to