Print alternative text if the query returns nothing

Hello,
I have the following html flask code where it prints some images and a title, what I want is that if it does not print anything because the query does not return anything, a text appears and if there is content, it prints that content.
I’m trying a few things but it’s not working for me.

{% for repor in tiporepor %}
          {% if repor|length %}
            <div class="col-xl-4 col-md-6" data-aos="zoom-in" data-aos-delay="200">
              <div class="service-item">
                
                <div class="img">
                  <!-- <img src="{{ img_path }}" class="img-fluid" alt=""> -->
                  <img src="{{ url_for('static', filename=repor[5]) }}" class="img-fluid" alt="">
                  <!-- <img src="{{ url_for('static', filename='img/services-1.png') }}" class="img-fluid" alt=""> -->
                </div>
                <div class="details position-relative">
                  <div class="icon">
                    <i class="bi bi-activity"></i>
                  </div>
                  <a href="{{url_for('view_repor', id_repor=repor[0])}}" class="stretched-link">
                    <h3>{{repor[1]}}</h3>
                  </a>
                  <p>{{repor[4]}}</p>
                </div>
              </div>
            </div><!-- End Service Item -->
            {% else %}
            <p>NO EXISTE NINGUN INFORME PARA TI EN ESTE APARTADO - VOLVER</p>
          {% endif %}
        {% endfor %}

thank you so much

It’s usual for a return value to be False or Null, if nothing is returned and as such, you should be able to do a simple if/else branch:

if query:
    print(query)
else:
    print(message)

To add: although that’s a little simplistic, it’s the basic premise, but maybe you don’t mean ‘… the query returns nothing’, rather, it returns empty fields, or something like that, in which case, maybe the solution is up stream, and the return needs to be filtered some more, before anything is returned.

What happens when you try it, and how is that different from the expected result? Did you check the page source after making the request, in order to make sure of what is actually being sent to the browser? (Did you also check the inspector view in the browser’s console, to make sure of what happens when any JavaScript runs?)

I finally checked the app.py

Depending on the verification it goes to one template or another

tiporepor = obtener_report_por_id_user(db,usuario,agrupacion,tipo_repor)
    try:
        if tiporepor[0][2]:
            return render_template('panel_workspace.html', tiporepor=tiporepor, version=__version__)
    except IndexError:
        return render_template('panel_workspace_2.html', tiporepor=tiporepor, version=__version__)