2017-11-25 159 views
0

我正在使用Flask和Blueprints製作複雜的應用程序。當我運行它並使用「/」路徑請求模塊索引功能時,它工作得很好。但是,只要我添加另一個頁面/函數(例如/下面的示例中的驗證程序/ dhashboard或任何其他),它就會將此鏈接路由到404.瓶頸URL路由在所有頁面上失敗,但索引(/)

這是我的「backoffice」模塊之一的代碼所謂的 「驗證器」:

from flask import Blueprint, render_template 

from backoffice import login_required 
from backoffice import app 


# Define Blueprint 

mod_verificator = Blueprint("verificator", __name__, url_prefix='/verificator/', template_folder="templates") 


@mod_verificator.route('/', methods=['GET', 'POST']) 
@login_required 
def verificator(): 
    return render_template("verificator.html") 


@mod_verificator.route('/dashboard/', methods=['GET', 'POST']) 
def dashboard(): 
    return render_template("dashboard.html") 


# Register blueprint(s) 
app.register_blueprint(mod_verificator) 

和日誌輸出:

2017-11-25 22:55:14,614 : DEBUG : verificator: 12: <module> : _ name _: backoffice.mod_verificator.verificator 
2017-11-25 22:55:14,614 : DEBUG : verificator: 13: <module> : mod_name : verificator 

2017-11-25 22:57:17,459 : INFO : _internal: 87: _log : 127.0.0.1 - - [25/Nov/2017 22:57:17] "GET /verificator/ HTTP/1.1" 200 - 
2017-11-25 22:57:40,902 : INFO : _internal: 87: _log : 127.0.0.1 - - [25/Nov/2017 22:57:40] "GET /verificator/dashboard/ HTTP/1.1" 404 - 

如此, 「驗證器」 模塊渲染模板(200和HTTP代碼)和驗證器/儀表板失敗慘與404

我完全失去了,並尋求你的幫助!

+1

奇怪...也許溝結尾的斜線:'url_prefix =「/驗證器」 '在Blueprint實例化中(我總是這樣定義它們) – abigperson

回答

2

根據您url_prefix設置,可以設置尾部的斜槓爲/verificator/,如果你想獲得儀表盤,你需要的網址,您的瀏覽器:

http://127.0.0.1:5000/verificator//dashboard/

不過,你最好刪除結尾的斜線是/verificator,這樣就可以通過訪問:

http://127.0.0.1:5000/verificator/dashboard/

+0

確實有效。很簡單!非常感謝! – uzla