【发布时间】:2015-07-26 14:06:50
【问题描述】:
我有一个用 HTML 编写的网页,操作是使用 JQuery 完成的。下面的 html 代码没有使用任何 JQuery,但我想我会提到这一点,因为我可能需要在其中放置一些 AJAX。
这里是“前端”
index.html
<!DOCTYPE html>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="javaScript.js"></script>
<html>
<div id="liveOutputTitle">
<h1><span>Live Output</span></title>
</div>
<div id="liveOutput">
Value 1 From Python: <input type="text" name="Value1" id="Value1" value="0"><br>
Value 2 From Python: <input type="text" name="Value2" id="Value2" value="0"><br>
Value 3 From Python: <input type="text" name="Value3" id="Value3" value="0"><br>
</div>
我有一个 JQuery 文件,它不会影响我放入 html 文件中的任何内容。但这里是对该文件的引用。
jquery.js
$(document).ready(function(){
//logic for other functionality of the site
//I'm assuming some AJAX goes here
});
我的最终目标是拥有一个从某个地方提取值的 python 程序,我希望这些值显示在输入字段中。
我的python“服务器端”代码。执行以下操作:
serverSide.py
#!/usr/bin/env python
def getValueOne():
//gets the value from wherever
valueOne = 1
def getValueTwo():
//gets the value from wherever
valueTwo = 2
def getValueThree():
//gets the value from wherever
valueThree = 3
如何在 python 中获取此处的值,以便在这些值更改时显示为 HTML 中的相应输入值?
我已经尝试使用一些关于 AJAX 的教程来解决这个问题,但我还没有设法将逻辑完全结合在一起。我已经阅读了this、this 和this,但我仍然不确定如何连接这个逻辑。任何帮助表示赞赏。
编辑 1
我相信有人会说我应该提到我想要使用的框架(假设你必须使用框架)。我不确定,但我读过很多关于flask的文章,如果我必须随机选择一个,我会使用flask。
【问题讨论】: