Search code examples
flaskjinja2

Flask Jinja Template Condition Based on Blueprint View


I haven't seen mention of this in the documentation, but is it possible to have a variable in a template based on what blueprint view is being used? This relates to my base.html and in one blueprint I want to have a different navbar, but I don't want to need to set this for every route/view in that blueprint specifically, nor have multiple base.html for each blueprint either.


Solution

  • The request object contains a property blueprint, which contains the registered name of the current blueprint. You should be able to render different code based on that.