【发布时间】:2018-02-01 19:27:22
【问题描述】:
我编写了一个 html 代码,它将从用户那里获得 3 个输入。 我附上了html代码sn-p如下; 您可以尝试运行此代码。这段代码基本上接受来自用户的 3 个值,它们是 team1、team2 和 match_id,点击预测按钮后,我希望这些值进入我编写机器学习算法的 python 脚本中。
<!DOCTYPE html>
<html>
<head>
<title>Criclytics</title>
<link rel="stylesheet" href="bootstrap.min.css">
<script src="bootstrap.min.js"></script>
<script src="jquery.min.js"></script>
<style type="text/css">
@import url(http://fonts.googleapis.com/css?family=Exo:100,200,400);
@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:700,400,300);
body{
margin: 0;
padding: 0;
background: #fff;
color: black;
font-family: Arial;
font-size: 25px;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
.bcg-img{
width: 100vw;
height: 100vh;
z-index: -1;
position: fixed;
background-image: url("bg-blurred.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
table, td, th {
text-align: center;
}
table {
border-collapse: collapse;
width: 50%;
}
th, td {
padding: 15px;
}
.button1 {width: 250px;}
</style>
</head>
<body>
<div class="bcg-img"></div>
<div class="jumbotron" align="center" style="opacity:0.60">
<h1 align="center"><b>Criclytics</b></h1>
Predicting chances of winning
</div>
<form onsubmit="http://localhost:5000/">
<div class="col-xs-3">
<label for="ex2">Team 1</label>
<input class="form-control" id="team1" id="team1" type="text" placeholder="Enter team 1">
</div>
<div class="col-xs-3">
<label for="ex2">Team 2</label>
<input class="form-control" id="team2" id="team2" type="text" placeholder="Enter team 2">
</div>
<div class="col-xs-3">
<label for="ex2">Match ID:</label>
<input class="form-control" id="matchid" id="matchid" type="number" placeholder="Enter match ID ">
</div>
<br>
<input type="submit" value="Predict" class="btn btn-info btn-lg" style="width: 250px"/>
<!--
<div width="cover" padding="30%"><!--put your graph here</div>-->
</form>
</body>
</html>
我正在使用flask在localhost:5000上创建服务器,我已经编写了代码,如下;
from flask import Flask, render_template
from flask import request
app = Flask(__name__)
print("hello")
@app.route('/')
def getrender():
return render_template('/cric.html')
@app.route('/',methods=['GET','POST'])
def getinfo():
if request.method == 'GET':
a=request.args.get('team1')
b=request.args.get('team2')
c=request.args.get('matchid')
print(a,b,c)
return a,b,c
if __name__=='__main__':
app.run(debug=True)
html 文件在 localhost:5000 上完美运行,但我不知道如何访问这些用户输入值并将其用作我的机器学习算法的输入。 我只想帮助如何访问这些 team1、team2 和 match_id 并将它们放入变量中,以便我可以在我的程序中使用它们。
【问题讨论】:
-
print(a, b, c) 时控制台会打印什么值
-
程序运行时控制台上没有打印任何内容
-
在 localhost:5000 上输入值后重新运行程序时,我在屏幕上看到的只是“使用 stat 重新启动”
-
为什么getinfo和getrender使用同一个url?