Flask:为什么我收到404错误?

时间:2017-02-10 22:58:48

标签: python html flask

我正在研究我的Flask技能,以制作一个“Jeopardy得分守护者”应用程序。我现在要做的是从数据库中获取玩家的分数并将其显示在屏幕上。我一直收到“404 NOT FOUND”错误。这是我的代码:

JeopardyApp.py

@app.route('/layout', methods=['POST'])
def layout():
    db = get_db()
    try:
        cur1 = db.execute('SELECT score FROM {tn} where name="Tyler"'.format(tn="Score"))
        score1 = cur1.fetchone()
    except:
        flash("This person doesn't exist in our database!")
    return render_template('layout.html', score=score1)

的layout.html

<!doctype html>
<title>JeopardyApp</title>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
<div class=page>
  <h1>Jeopardy Score Keeper</h1>
  <div class=metanav>
    <p>Currently under construction...</p>
  </div>

  <div>
    <p>Tyler</p>
          <tr><td>{{ score.score }}</td></tr>
  </div>

  {% for message in get_flashed_messages() %}
    <div class=flash>{{ message }}</div>
  {% endfor %}
  {% block body %}{% endblock %}
</div>

感谢任何帮助。谢谢。

1 个答案:

答案 0 :(得分:0)

您为layout功能设置的路由只能通过POST方法访问。 默认情况下,您的Web浏览器使用GET方法。

以这种方式改变你的路线:

@app.route('/layout', methods=['GET'])
相关问题