Flask: current page in request variable

前端 未结 6 895
悲&欢浪女
悲&欢浪女 2020-12-04 16:41

In a template, how do I get what page I\'m currently on? I\'d rather not pass a variable like page , especially when I know some request.xxx can pr

6条回答
  •  感动是毒
    2020-12-04 16:59

    Using request.path doesn't seem to be a proper approach since you'll have to update the paths in case of changing URL rules or deploying your site under a subfolder.

    Use request.url_rule.endpoint instead, it contains actual endpoint name independent of actual path:

    (Pdb) request.url_rule.endpoint
    'myblueprint.client_pipeline'
    

    In a template:

  • Home
  • Good luck!

提交回复
热议问题