据我所知,下面的脚本正在接受用户输入并运行脚本,有人能告诉我如何在脚本运行后输出结果吗?你知道吗
app = Flask(__name__)
这是脚本本身。你知道吗
def elastic_search(text):
es = Elasticsearch(['10.0.0.9:9200', '10.0.0.15:9200'])
word = input(text)
res = es.search(index="pastebin-*", doc_type='doc', body={"query": {"bool": {"must": [{"match": {"key": word}}]}}})
return res
这是接受输入并运行脚本的函数
@app.route('/key', methods=['POST', 'GET'])
def key():
if requests.method == 'POST', 'GET':
result = request.form['key']
elastic_search(result)
return render_template('key.html')
这是我希望在脚本运行后显示其结果的函数。你知道吗
@app.route('/result', methods=['POST', 'GET'])
def result():
if request.method == 'POST':
result = request.form
return render_template('result.html', result = result)
if __name__ == '__main__':
app.run('0.0.0.0')
app.run(threaded=True)
这是结果页面的html-
<!DOCTYPE html>
<html lang="en">
<head>
<title>Results</title>
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" rel="stylesheet">
<link href="../static/result.css" rel="stylesheet">
</head>
<body>
<table border = 1>
{% for key, value in result.res() %}
<tr>
<th> {{ resp }} </th>
</tr>
{% endfor %}
</table>
</form>
{% if error %}
<p class="error"><strong>Error:</strong> {{ error }}
{% endif %}
</div>
<footer class="footer">
<p>© Intel</p>
</footer>
</div>
</body>
</html>
这里是密钥.html你知道吗
<!DOCTYPE html>
<html lang="en">
<head>
<title>Key</title>
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="styleshee$>
<link href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" rel="stylesheet">
<link href="../static/key.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div class="header">
<h3 class="text-muted"><Key/h3>
</div>
<div class="jumbotron">
<h1>Please Enter Pastebin Key</h1>
<form class="form-signin">
<form action="" method"post">
<label for="Key" class="sr-only">Key</label>
<input type="text" name="inputKey" id="inputKey" class="form-control" placeholder="Enter key here" required value="{{request.form.key }}">
<input type="submit" value="Submit">
</form>
{% if error %}
<p class="error"><strong>Error:</strong> {{ error }}
{% endif %}
</div>
<footer class="footer">
<p>© Intel</p>
</footer>
</html>
我知道这是混乱的,但我是新的烧瓶,并在一个不知所措的尝试什么是错误的代码。我读了很多教程,但没有一本对我有帮助。你知道吗
给出了不清楚的信息。我想这就是你想要的
您需要设置
key.html
表单来调用结果路由。e、 g.localhost:8000/result
你的结果.html-假设返回结果
相关问题 更多 >
编程相关推荐