亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何獲取燒瓶中的最后一個條目

如何獲取燒瓶中的最后一個條目

一只萌萌小番薯 2023-08-22 16:46:22
我試圖從quizlist.html 輸入中獲取最后一個條目并將其放在test.html 上。我通過 app.py 綁定但沒有成功,也嘗試從 html 頁面本身但沒有成功。我不是專家,但我認為我的數據保存在會話中,而不是像我一樣保存在 sqlalchemy 中。這不是問題,我只是想從 html 頁面獲取最后一個條目并將其放在另一個 html 頁面上。場景是,當用戶填寫文本輸入時,所有數據(因為用戶可以輸入多次)將作為表格打印在 result.html 上。我只想在 test.html 上打印最后一個條目這是我的 app.py<!DOCTYPE html><html>   <head>      <script src="https://cdn.jsdelivr.net/gh/linways/[email protected]/dist/tableToExcel.js"></script><script>function exportReportToExcel() {  let table = document.getElementsByTagName("table");  TableToExcel.convert(table[0], {    name: `Questions & Answers.xlsx`,    sheet: {      name: 'Sheet 1'    }  });}</script>   </head>   <body style="font-family: Arial, Helvetica, sans-serif;  background-color: #FFFAFA;"><div   style="width:800px; margin:0 auto;">      <h3>         <a style="color:#14568B;" href = "{{ url_for('result') }}"> Click to Show Table of Questions and Answers</a>      </h3>      <hr/>      {%- for message in get_flashed_messages() %}         {{ message }}      {%- endfor %}      <h3> (<a style="color:#14568B;" href = "{{ url_for('quickQuizList') }}">Click to Add Quick Quiz Question         </a>)</h3>      <table style="border: 1px solid black;">         <thead>            <tr width="380" style="border: 20px solid black ;">               <th width="80" style="border: 1px solid black ;">TF Question</th>               <th width="80" style="border: 1px solid black ;">TF Answer</th>               <th width="80" style="border: 1px solid black ;">MCQ Question</th>               <th width="80" style="border: 1px solid black ;">MCQ Answer</th>            </tr>         </thead>
查看完整描述

1 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

您正在使用從數據庫中檢索所有對象quickQuizQuestions.query.all()。

您只想檢索一個對象;您的最后一個條目。如果您的問題 ID 確實增加,您可以通過以下方式執行此操作:

quickQuizQuestions.query.order_by(-quickQuizQuestions.id).limit(1).all()

或者

quickQuizQuestions.query.order_by(-quickQuizQuestions.id).first()


查看完整回答
反對 回復 2023-08-22
  • 1 回答
  • 0 關注
  • 1379 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號