这种 Flask 路由的方法合理吗?
is this approach to Flask routing reasonable?
我将每条路径都指向 index.html,因为它是一个单页应用程序。我制作了一个名为 mod 的蓝图,并使用 flask-restful
将所有 restul api 放在那里
@mod.route('/')
@mod.route('/<path:p>')
def home(p=0):
return render_template('index.html')
这是正确的做法吗?
我不太关心 p=0 部分。
变量 p 从未使用过,但必须存在,因为它必须接收路径变量 p
你的路由肯定是合理的。
更 simple/readible 的方法可能是:
@mod.route('/')
@mod.route('/<path>')
def home(*args, **kwargs):
return render_template('index.html')
从效率的角度来看,最好完全在网络服务器上处理 (nginx/apache/whatever)。
我将每条路径都指向 index.html,因为它是一个单页应用程序。我制作了一个名为 mod 的蓝图,并使用 flask-restful
将所有 restul api 放在那里@mod.route('/')
@mod.route('/<path:p>')
def home(p=0):
return render_template('index.html')
这是正确的做法吗? 我不太关心 p=0 部分。 变量 p 从未使用过,但必须存在,因为它必须接收路径变量 p
你的路由肯定是合理的。
更 simple/readible 的方法可能是:
@mod.route('/')
@mod.route('/<path>')
def home(*args, **kwargs):
return render_template('index.html')
从效率的角度来看,最好完全在网络服务器上处理 (nginx/apache/whatever)。