[Python] Django Template Tags Creating Spaces

Discussão em 'Python' iniciado por Stack, Setembro 16, 2024.

  1. Stack

    Stack Membro Participativo

    I am working on a Django site which is live at this site. I am getting unwanted spaces in my output caused by unwanted whitespace in the HTML.

    For instance, "01-1737 , Civilian Review Authority , INAPPROPRIATE LANGUAGE, SUSTAINED," has extra spaces before most of the commas.

    I have found other posts with similar problems, but no solution has worked for me. I tried the {% spaceless %} tag, but that didn't work. The only thing that did work for me was putting all of the template tags in the for loop on a single line, but I'd really like to find a more readable solution than this.

    Here is the code for the Django template:

    {% extends 'police_archive/base.html' %}

    {% block content %}
    <h2> {{officer.first_name}} {{officer.last_name}}, badge #{{officer.badge}} </h2>
    <p><strong>Department:</strong> {{officer.department}}</p>
    <h2>Complaints</h2>
    <ul>
    {% for details in details_list %}
    <li>


    {% if details.incident.case_number %}
    <a href='/police_archive/complaint/{{details.incident.case_number}}'>
    {{details.incident.case_number}}
    </a>
    {% else %}
    No Case Number Found
    {% endif %}


    {% if details.incident.office %}
    , {{details.incident.get_office_display}}
    {% else %}
    , No office found
    {% endif %}

    {% if details.allegation %}
    , {{details.allegation}}
    {% endif %}

    {% if details.finding %}
    , {{details.finding}}
    {% endif %}

    {% if details.action %}
    , {{details.action}}
    {% endif %}

    </li>
    {% endfor %}


    {% endblock %}

    Continue reading...

Compartilhe esta Página