Python 在cs50财务解决方案中不显示历史记录表
我目前正在与cs50的财务解决方案进行正面碰撞 似乎除了历史记录表之外,我还成功地完成了所有操作,因为当单击历史记录链接时,没有显示任何内容,但我也没有收到任何错误消息 这是application.py中的我的历史记录代码:Python 在cs50财务解决方案中不显示历史记录表,python,html,web,finance,stock,Python,Html,Web,Finance,Stock,我目前正在与cs50的财务解决方案进行正面碰撞 似乎除了历史记录表之外,我还成功地完成了所有操作,因为当单击历史记录链接时,没有显示任何内容,但我也没有收到任何错误消息 这是application.py中的我的历史记录代码: @app.route("/history") @login_required def history(): rows = db.execute("SELECT * FROM transactions WHERE user_id = :u
@app.route("/history")
@login_required
def history():
rows = db.execute("SELECT * FROM transactions WHERE user_id = :user",
user=session["user_id"])
transactions = []
for row in rows:
stock_info = lookup(row['symbol'])
if row['isbought'] == '0':
row['value'] = "-" & row['value']
transactions.append(list((stock_info['symbol'], stock_info['name'], row['shares'], usd(row['value']), row['transacted'])))
return render_template("history.html", transactions=transactions)
这是my history.html:
{% extends "layout.html" %}
{% block title %}
History
{% endblock %}
{% block body %}
<table class="table">
<thead>
<th>SYMBOL</th>
<th>NAMES</th>
<th>SHARES</th>
<th>VALUE</th>
<th>DATE</th>
</thead>
<tbody>
{% for transaction in transactions %}
<tr>
<th scope="row">{{ transaction[0] }}</th>
<td>{{ transaction[1] }}</td>
<td>{{ transaction[2] }}</td>
<td>{{ transaction[3] }}</td>
<td>{{ transaction[4] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
{%extends“layout.html”%}
{%block title%}
历史
{%endblock%}
{%block body%}
象征
名字
分享
价值
日期
{交易记录%中的交易记录为%0}
{{事务[0]}
{{事务[1]}
{{事务[2]}
{{事务[3]}
{{事务[4]}
{%endfor%}
{%endblock%}
如果您需要查看我的代码的其余部分,请在下面进行评论。我将非常感谢任何帮助调试我的工作 为什么在
返回渲染模板之前使用&in行['value']=“-”&row['value']
。
添加打印(len(交易))
,您将看到表中应该有多少行。@Advay168我想在出售交易时以负值显示交易价格。您建议如何执行此操作?行['value']
是字符串还是整数?如果是字符串,则写入行['value']=“-”+行['value']
否则行['value']=-行['value']