【发布时间】:2019-05-15 07:07:41
【问题描述】:
我的 app.py 是
app=flask.Flask(__name__,template_folder='templates')
@app.route('/')
def main():
if flask.request.method == 'GET':
return(flask.render_template('main.html'))
if flask.request.method == 'POST':
news = flask.request.form['article']
input_variables = pd.DataFrame([[news]],
columns=['news'],
dtype=object)
prediction = model.predict(input_variables)[0]
return flask.render_template('main.html',
original_input={'news':news},
result=prediction,
)
if __name__=='__main__':
app.run()
<!doctype html>
<html>
<style>
form {
margin: auto;
width: 35%;
}
.result {
margin: auto;
width: 35%;
border: 1px solid #ccc;
}
</style>
<head>
<title>News Classification Model</title>
</head>
<form action="{{ url_for('main') }}" method="POST">
<fieldset>
<legend>Input values:</legend>
Enter any news:
<input name="news" type="object" required>
<br>
<br>
<input type="submit">
</fieldset>
</form>
<br>
<div class="result" align="center">
{% if result %}
{% for variable, value in original_input.items() %}
<b>{{ variable }}</b> : {{ value }}
{% endfor %}
<br>
<br> Predicted Class of the news :
<p style="font-size:50px">{{ result }}</p>
{% endif %}
</div>
</html>
【问题讨论】:
-
404错误意味着请求甚至没有到达烧瓶应用程序。忘记 html,检查你的服务器配置,即 nginx/apache、gunicorn 和/或你在后端使用的任何东西来运行这个应用程序。如果它是 Amazon EC2 实例,还要检查您的防火墙。 -
你能展示一下你的项目的结构吗?您的 main.html 在哪个文件夹中?你确定把它放在 templates 文件夹里吗?