python flask for loop cannot print the right data

Viewed 27

this is part of my html code

<tbody>
            {% for row in patent %}
            <tr>
                ...
                <td>
                  <p class = 'short'>{{row.4}}</p>
                  <!-- https://bootstrap5.hexschool.com/docs/5.0/components/modal/ -->
                  <!-- Button trigger modal -->
                  <button type="button" class="btn btn-light btn-sm" data-bs-toggle="modal" data-bs-target="#staticBackdrop">
                    show more
                  </button>

                  <!-- Modal -->
                  <div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
                    <div class="modal-dialog modal-dialog-scrollable">
                      <div class="modal-content">
                        <div class="modal-header">
                          <h5 class="modal-title" id="staticBackdropLabel">{{row.3}}</h5>
                          <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                          <p>{{row.4}}</p>
                        </div>
                        <div class="modal-footer">
                          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">close</button>
                        </div>
                      </div>
                    </div>
                  </div>
                </td>
                ...
            </tr>
          {% endfor %}
</tbody>

i simplify some code.

as the title, i don't know why this for loop cannot print the right answer for me.

  • 2nd line: patent is a database, i print data by row from patent
  • 6th line: {{row.4}} can print the right value on the web
  • 8th line: button trigger modal is a modal from bootstrap, 'cause i'm tying to use modal to show the text from patent

here is the question, {{row.4}} can print the right value normally, but whatever is {{row.3}} or {{row.4}} in modal's code (18th and 22nd lines), they always print the first value in database.

i don't know where is the problem.

here is flask code

@app2.route('/home',  methods=['GET', 'POST'])

def index():

        type = "main index"
        connect_mysql()

        cursor.execute('SELECT patent_nums,application_dates,IPCs,titles,abstracts,claimses FROM all_patent')
        data = cursor.fetchall()
        cursor.close()

        return render_template('index.html', patent = data, type_name = type)

so does anyone can tell me any solution? thx a lot~

and so sorry about my english grammar

0 Answers
Related