<!DOCTYPE html>

<html>

<head>
    <title>Server status page</title>
</head>

<body>
    <h1>Server status</h1>
    <h2>Free disk space</h2>
    {% for item in render_items %}
        {% if item.free_space > 1024**3 %}
            {% set size_divisor = 1024**3 %}
            {% set size_symbol = 'GB' %}
        {% elif item.free_space > 1024**2 %}
            {% set size_divisor = 1024**2 %}
            {% set size_symbol = 'MB' %}
        {% elif item.free_space > 1024 %}
            {% set size_divisor = 1024 %}
            {% set size_symbol = 'KB' %}
        {% else %}
            {% set size_divisor = '1' %}
            {% set size_symbol = '' %}
        {% endif %}
    <p>{{ item.volume }}: {{ item.free_space // size_divisor }} {{ size_symbol }}</p>
    {% endfor %}
</body>

</html>

<!DOCTYPE html>

{% macro human_size(bytes) %}
    {% if bytes > 1024**3 %}
        {% set size_divisor = 1024**3 %}
        {% set size_symbol = 'GB' %}
    {% elif bytes > 1024**2 %}
        {% set size_divisor = 1024**2 %}
        {% set size_symbol = 'MB' %}
    {% elif bytes > 1024 %}
        {% set size_divisor = 1024 %}
        {% set size_symbol = 'KB' %}
    {% else %}
        {% set size_divisor = '1' %}
        {% set size_symbol = '' %}
    {% endif %}
    {{ bytes // size_divisor }}{{ size_symbol }}
{% endmacro %}

<html>

<head>
    <title>Server status page</title>
</head>

<body>
    <h1>Server status</h1>
    <h2>Free disk space</h2>
    {% for item in render_items %}
        <p>{{ item.volume }}: {{ human_size(item.free_space) }}</p>
    {% endfor %}
</body>

</html>

Split size pretty printing into macro
Split size pretty printing into macro
