我有一个简单的“投票”网页,其中向用户展示了一个包含三列的表格。每列将包含搜索引擎查询的结果,然后用户将选择哪一列具有更好的结果并单击按钮。
这是一个示例:http: //jsfiddle.net/rfeGa/
我需要以下帮助: 1. 如何跟踪 html 页面和 python 程序之间的投票?2. 我想在 python 文件中保留查询列表,我如何将该信息传递给网页?
这是我的html页面:
<!DOCTYPE html>
<html>
<head>
<title>Search Engine Comparator!</title>
</head>
<body>
% queries = ("ccny", "bmcc", "qcc");
% bingScore = googScore = yhooScore = 0;
% for q in queries:
The query is: {{ q }}
<br />
And the scores are: Bing = {{ bingScore }}, Google = {{ googScore }}, Yahoo = {{ yhooScore }}.
<hr>
<form action="/" method="post">
<table border="1" width="100%">
<tr>
<th>
<input type="submit" name="engine1" value="Engine 1 is better!" />
</th>
<th>
<input type="submit" name="engine2" value="Engine 2 is better!" />
</th>
<th>
<input type="submit" name="engine3" value="Engine 3 is better!" />
</th>
</tr>
</table>
</form>
% end
</body>
</html>
<script type="text/javascript">
</script>
这是我的python代码:
from bottle import request, route, run, view
from mini_proj import *
@route('/', method=['GET', 'POST'])
@view('index.html')
def index():
return dict(parts = request.forms.sentence.split(),
show_form = request.method == 'GET');
run(host = 'localhost', port = 9988);