【发布时间】:2021-12-30 09:50:36
【问题描述】:
我正在做一个小项目,我想将变量“x”的值从 javascript 传递给 pyhthon 变量 get_x。有人可以帮助我如何做到这一点。
index.html:
<html>
<body>
<p id="msglog"></p>
<input type="text" id="msg">
<button onclick="myFunction()">></button>
</body>
<script>
function myFunction() {
var x = document.getElementById("msg").value;
document.getElementById("msglog").innerHTML = x;
return x
}
</script>
</html>
main.py:
from flask import Flask, render_template
app = Flask(__name__,template_folder='',static_folder='')
@app.route("/")
def mainpage():
return render_template('/index.html')
app.run(host='0.0.0.0')
【问题讨论】:
-
是什么让你认为这是可能的?
-
你应该从你的 JS 代码向 python 发出一个 post 请求
标签: javascript python flask web-development-server