2017-08-20 92 views
4

我正在使用Flask和React。我想創建一個捕捉類似這樣的事情的所有航線(雖然這不工作):抓住Flask的所有路線

@app.route('*') 
def get(): 
    return render_template('index.html') 

由於我的應用程序將使用反應,它使用的index.html安裝我的反應的組分,我希望每個路由請求都指向模板中的index.html頁面。有沒有辦法做到這一點(或使用重定向最好的方式)?

回答

5

您可以按照本指南:http://flask.pocoo.org/snippets/57/

from flask import Flask 
app = Flask(__name__) 

@app.route('/', defaults={'path': ''}) 
@app.route('/<path:path>') 
def catch_all(path): 
    return 'You want path: %s' % path 

if __name__ == '__main__': 
    app.run()