首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我的网页在添加对象后不返回更新的列表?使用瓶

为什么我的网页在添加对象后不返回更新的列表?使用瓶
EN

Stack Overflow用户
提问于 2022-11-09 03:45:44
回答 1查看 33关注 0票数 0

这是我的python代码。你知道哪里出了什么问题吗?我正在使用烧瓶来托管本地的web服务器。我没有HTML或CSS方面的经验,所以我使用我的课程提供的模板。我能够成功地运行该程序,但是如果我通过网页添加支票或存款,那么应该显示所有事务的网页是空的,尽管前面添加了列表。

代码语言:javascript
运行
复制
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)

我试着自己想办法解决这个问题,但没有成功。如有任何建议,敬请见谅。

支票/存款页 事务页

EN

回答 1

Stack Overflow用户

发布于 2022-11-09 03:53:24

您还能共享checkbook-result.html吗?因为数据的显示或输出发生在模板上,谢谢

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74369702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档