nav li a[href="{% url 'cart' %}"] {
    position: relative;
}

nav li a[href="{% url 'cart' %}"]::after {
    content: "{{ cart|length }}";
    position: absolute;
    top: -10px;
    right: -10px;
    background-color: red;
    color: white;
    border-radius: 50%;
    padding: 5px;
    font-size: 0.8em;
    font-weight: bold;
    line-height: 1;
}