2017-02-10 81 views
1

我正在刷我的燒瓶技能來製作一個「危險分數守護者」應用程序。我現在想要做的是從數據庫中獲取玩家的分數並將其顯示在屏幕上。我不斷收到「404 NOT FOUND」錯誤。這裏是我的代碼:燒瓶:我爲什麼會收到404錯誤?

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> 

任何幫助表示讚賞。謝謝。

回答

0

您爲layout功能設置的路線只能通過POST方法訪問。 默認情況下,您的網頁瀏覽器使用GET方法。

改變你的路線是這樣的:

@app.route('/layout', methods=['GET']) 
+0

我試過了,我仍然得到同樣的錯誤:( – HereComesDatBoi

+0

這應該實際工作是您使用的URL來調用'layout'端點 – MrLeeh

+0

?我不知道我做了什麼,但我確實得到了這個工作,我認爲我的URL或app.route是不正確的,但是,我現在很好,謝謝! – HereComesDatBoi