这是我的python代码。你知道哪里出了什么问题吗?我正在使用烧瓶来托管本地的web服务器。我没有HTML或CSS方面的经验,所以我使用我的课程提供的模板。我能够成功地运行该程序,但是如果我通过网页添加支票或存款,那么应该显示所有事务的网页是空的,尽管前面添加了列表。
from flask import Flask, render_template, request
app = Flask(__name__)
register_items = []
balance = 0.0
@app.route('/')
def home():
return render_template("checkbook-form.html")
@app.route('/transaction', methods=['POST'])
def compute():
global balance
# For a POST request to /transaction, request.form is a dictionary that contains the posted
# form data. It should have values for 'number', 'date', 'description', and 'amount'.
# Convert 'amount' to float and add it to the balance.
# Create a dictionary with the values for 'number', 'date',
# 'description', 'amount', and balance, and append the dictionary to the
# register_items list so the user can see the new entry in the results.
number = request.form["number"]
date = request.form["date"]
description = request.form["description"]
amount = float(request.form["amount"])
balance = balance + amount
dictionary = {1: number, 2: date, 3: description, 4: amount, 5: balance}
register_items.append(dictionary)
# Render the output page. Send the register_items list to the page to show to the user:
return render_template("checkbook-result.html", content=register_items)
# hosted on localhost, which is http://localhost:8080/
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=8080)我试着自己想办法解决这个问题,但没有成功。如有任何建议,敬请见谅。
发布于 2022-11-09 03:53:24
您还能共享checkbook-result.html吗?因为数据的显示或输出发生在模板上,谢谢
https://stackoverflow.com/questions/74369702
复制相似问题