Flask 如何接受未定义的路由
我可以在flask中定义许多路由Flask 如何接受未定义的路由,flask,Flask,我可以在flask中定义许多路由 @app.route('/') @app.route('/schedules/<params>', methods=["GET"]) @app.route(“/”) @app.route('/schedules/',methods=[“GET”]) 但是,如何拦截我的应用程序中未定义的任何其他路由。以下内容如何 @app.route('/<generic>') 下面呢 @app.route('/<generic>')
@app.route('/')
@app.route('/schedules/<params>', methods=["GET"])
@app.route(“/”)
@app.route('/schedules/',methods=[“GET”])
但是,如何拦截我的应用程序中未定义的任何其他路由。以下内容如何
@app.route('/<generic>')
下面呢
@app.route('/<generic>')
下面呢
@app.route('/<generic>')
下面呢
@app.route('/<generic>')
我已经实现了一个catch_all功能,它将采用请求的路径并尝试返回一个具有该名称的html文件,如果失败,它将重定向到索引
@WebApp.app.route('/<path:path>', methods=['GET', 'POST'])
def catch_all(path):
url = path+".html"
try:
return flask.render_template(url)
except:
return flask.redirect(flask.url_for('index'))
@WebApp.app.route('/',方法=['GET','POST'])
def catch_all(路径):
url=path+“.html”
尝试:
返回flask.render_模板(url)
除:
返回flask.redirect(flask.url_表示('index'))
我已经实现了一个catch_all功能,它将采用请求的路径并尝试返回一个具有该名称的html文件,如果失败,它将重定向到索引
@WebApp.app.route('/<path:path>', methods=['GET', 'POST'])
def catch_all(path):
url = path+".html"
try:
return flask.render_template(url)
except:
return flask.redirect(flask.url_for('index'))
@WebApp.app.route('/',方法=['GET','POST'])
def catch_all(路径):
url=path+“.html”
尝试:
返回flask.render_模板(url)
除:
返回flask.redirect(flask.url_表示('index'))
我已经实现了一个catch_all功能,它将采用请求的路径并尝试返回一个具有该名称的html文件,如果失败,它将重定向到索引
@WebApp.app.route('/<path:path>', methods=['GET', 'POST'])
def catch_all(path):
url = path+".html"
try:
return flask.render_template(url)
except:
return flask.redirect(flask.url_for('index'))
@WebApp.app.route('/',方法=['GET','POST'])
def catch_all(路径):
url=path+“.html”
尝试:
返回flask.render_模板(url)
除:
返回flask.redirect(flask.url_表示('index'))
我已经实现了一个catch_all功能,它将采用请求的路径并尝试返回一个具有该名称的html文件,如果失败,它将重定向到索引
@WebApp.app.route('/<path:path>', methods=['GET', 'POST'])
def catch_all(path):
url = path+".html"
try:
return flask.render_template(url)
except:
return flask.redirect(flask.url_for('index'))
@WebApp.app.route('/',方法=['GET','POST'])
def catch_all(路径):
url=path+“.html”
尝试:
返回flask.render_模板(url)
除:
返回flask.redirect(flask.url_表示('index'))