【发布时间】:2020-05-03 09:26:37
【问题描述】:
我正在使用 python3,我有这个 HTMl,它创建了从 python 列表中获取的按钮:
</style>
</head>
<body>
<ul>
{% for thing in value %}
<form method="get" action="/loader" value="submit">
<button class="button button">{{ thing }}</button>
</form>
{% endfor %}
</ul>
</body>
</html>
我的python代码:
@app.route("/test", methods=["GET"])
def test():
a = ["a1","a2"]
return render_template('sbutton.html', value=a)
@app.route("/loader", methods=["GET"])
def loader():
data = request.args.get()
print(data)
return render_template('loader.html', value=password)
所以我会在http://localhost/test 网站上看到按钮 a1 和 a2
当我按下其中一个时,我将重定向到 /loader,这是我的 python 代码中到另一个 html 的路由。
我希望当我按下按钮时,例如a1,我会将此信息返回给我的 python
在loader 函数内。
我试过<form method="get" action="/loader" value="submit">
添加了value="submit,但我在print(data)下没有得到任何东西
我只需要知道客户端在我的代码中重定向到/loader 时单击了哪个按钮。
我想将此值保留为我的 python 中的 var。
谢谢
【问题讨论】:
-
你可以在这里查看。也许这可以帮助你[点击这里](stackoverflow.com/questions/53057621/…)
-
不,他正试图做相反的事情,我不想使用 django 但谢谢。我确定我的 HTML 是错误的。