这种方法合理吗?

2024-09-22 16:43:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使每一条路通向索引.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


Tags: pathapirestfulmod应用程序flaskhomereturn
1条回答
网友
1楼 · 发布于 2024-09-22 16:43:29

你的路线当然是合理的。你知道吗

更简单/易读的方法可能是:

@mod.route('/')
@mod.route('/<path>')
def home(*args, **kwargs):
    return render_template('index.html')

从效率的角度来看,完全在web服务器(nginx/apache/whatever)上处理这个问题可能更好。你知道吗

相关问题 更多 >