所以我一直在使用会话将数据从一个装饰器传递到另一个装饰器。但是现在每次我创建一个新的会话变量时,我都会在页面之间得到一个KeyError。意思是,我的第三页到第四页有一个会话错误;但我有同样的问题从我的第二页到第三页添加一个新的会话变量,即使我有四个其他会话变量给我没有错误。
我的代码与下面发布的@laila相似:
from flask import Flask, render_template
from flask import request, session, url_for,abort,redirect
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
@app.route('/'):
def first():
session['this_one']='hello'
render('template.html')
@app.route('/second')
def second():
it=session['this_one']
render('other_page.html')
if __name__ == '__main__':
app.run(debug=True)
答案 0 :(得分:-1)
似乎代码有一些语法错误。请尝试下面的代码,它应该没问题:
<table id="keywords" class="container">
<thead>
<tr>
<td><span>Project</span></td>
<td><span>No</span></td>
<td><span>Sub ID</span></td>
<td><span>Name</span></td>
<td><span>Requested Amount</span></td>
<td><span>Paid Amount</span></td>
<td><span>Amount To be Paid</span></td>
<td><span>Description</span></td>
<td><span>State</span></td>
</tr>
</thead>
<?php
/* showing table */
$sql = "SELECT * FROM memo ORDER BY No DESC, SubID ASC"
or die("Failed to query database" .mysqli_error());
$result = $link->query($sql);
while ($row = $result->fetch_assoc()) {
print "<tr>";
print "<td ><a href=\"Project.php?Project={$row['Project']}\">" . $row['Project'] . "</a></td>";
print "<td ><a href=\"PaymentVoucher.php?No={$row['No']}\">" . $row['No'] . "</a></td>";
print "<td >" . $row['SubID'] . "</td>";
print "<td ><a href=\"Name.php?Name={$row['Name']}\">" . $row['Name'] . "</a></td>";
print "<th >" . $row['RequestAmount'] . "</th>";
print "<th >" . $row['PaidAmount'] . "</th>";
print "<th >" . $row['AmountToPay'] . "</th>";
print "<td >" . $row['Description'] . "</td>";
print "<td >" . $row['State'] . "</td>";
print "</tr>";
}
// print "</table>";
?>
</table>