Flask:无法访问View(在服务器上找不到URL)

bcl*_*man 2 python flask

我正在尝试为Flask应用添加另一个视图.我的app/views.py看起来像这样:

from flask import render_template
from app import app
from helpfulFunctions import *

def getRankingList():
    allPlayers = main()
    return allPlayers

def displayLimitedNumberOfPlayers(limit):
    allPlayers = main()
    allPlayers[0] = limitPlayers(allPlayers[0], limit)
    allPlayers[1] = limitPlayers(allPlayers[1], limit)
    return allPlayers

@app.route("/")
@app.route("/index")
def index():
    rankingList = getRankingList()
    return render_template('index.html', title='Home', rankingList = rankingList)

@app.route("/top100")
def top100():
    rankingList = displayLimitedNumberOfPlayers(100)
    return render_template('top100.html', rankingList = rankingList)

if __name__ == '__main__':
    app.run(debug=True)
Run Code Online (Sandbox Code Playgroud)

我试图模仿Miguel Grinberg教程如何为for /和for 定义路由/index.我top100.html在我的模板文件夹中创建了一个视图,其中"index.html"文件也存在.但是,当我尝试击中时localhost:5000/top100.html,我得到:

Not Found

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.
Run Code Online (Sandbox Code Playgroud)

所以看起来Flask并不认为URL有与之相关的视图......但我不确定为什么.

任何的想法?

谢谢你的帮助,bclayman

itz*_*nTV 7

top100.html您的代码中没有视图.您可以执行其中任何一项操作

localhost:5000/top100
Run Code Online (Sandbox Code Playgroud)

要么

改变@app.route("/top100")@app.route("/top100.html")