setting and incrementing template variable

This always prints 1. I am trying to get numbers in a sequence (interval of 1) for all servers where server.isDeployed is False.

{% with counter=0 %}
{% for server in servers %}
    {% if server.isDeployed %}
    {% else %}
        {% with counter=counter|add:1 %}
            {{ counter }}
        {% endwith %}
    {% endif %}
{% endfor %}
{% endwith %}

Hello there!
Templates are not the best place to do this.

Do that on your view:

n = 1
for server in servers:
  if server.isDeployed:
     server._counter = 0  # probably not necessarily
  server._counter = n
  n += 1

Or if you also can move this check to the DB, you can annotate this value to not need to iterate twice.

Then, on the templates:

{% for server in servers %}
    {% if server._counter %}{{ counter }}{% endif %}
{% endfor %}

I actually want to show the results (non deployed servers) in a table where the # is from 1 - 15.

Well, then you can use the forloop.counter variable, documented here.
You will just need to make sure that the results are filtered for only non-deployed servers.

I don’t want non deployed servers filtered out because I’m displaying the whole table with all servers on the same page, and a table to show only non-deployed servers is present on a popup form. This popup form is an HTMX form and hence traditional page - thinking of using AlpineJS to filter them out for display.

Got it, in this case I would do 2 querysets then, one for the deployed and other for the non-deployed.
You can skip all of this overhead of filtering on the application and leave this job to the database, one an additional query probably wont hurt your database, and it will probably be easier to understand (in the future) what’s being accomplished.

Ah…Ok. Thanks for your input.