Get variables parsed from Flask URL

后端 未结 1 1220
滥情空心
滥情空心 2020-12-03 17:57

Suppose I have a simple route with a variable part:

@app.route(\'/post/\')
def show_post(post_id):
    return \'Post %d\' % post_id


        
相关标签:
1条回答
  • 2020-12-03 18:45

    Use request.view_args:

    @app.context_processor
    def provide_foo():
        if "post_id" in request.view_args:
            post_id = request.view_args["post_id"]
            return {"bar": some_function(post_id)}
    
    0 讨论(0)
提交回复
热议问题