假设我有一个带有可变部分的简单路径:
@app.route('/post/<int:post_id>')
def show_post(post_id):
return 'Post %d' % post_id
Run Code Online (Sandbox Code Playgroud)
现在我想注册一个上下文处理器
post_id使用参数调用视图函数时运行post_id,而不必再用例如重新解析URLre.match实质上:
@app.context_processor
def foo():
post_id = ???
return {'bar': some_function(post_id)}
Run Code Online (Sandbox Code Playgroud)
如果我可以从上下文处理器访问此示例中的**kwargs传递给我,我可以做到,但我发现无法做到这一点.有任何想法吗?show_post
flask ×1