From 11d6d851b2e3ea8298e93d9c8470fdf83e551692 Mon Sep 17 00:00:00 2001 From: girst Date: Thu, 30 Jul 2020 17:32:42 +0200 Subject: [PATCH] example blueprint: show how to add a header item --- app/example_plugin/__init__.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/example_plugin/__init__.py b/app/example_plugin/__init__.py index 41955d8..e959a2f 100644 --- a/app/example_plugin/__init__.py +++ b/app/example_plugin/__init__.py @@ -5,7 +5,7 @@ config/config.ini, under the [frontend] section, to the modules key (csv). first-named blueprints take precidence (which allows overwriting existing routes from other blueprints). """ -from flask import Blueprint +from flask import Blueprint, g, url_for from flask_login import current_user from ..common.common import * @@ -20,3 +20,14 @@ def index(name=None): if name == "world": return fallback_route(name) return f"hello, {name or 'you'} from user {token}!" # note: token is usually not a username, but a random string + +@frontend.before_app_request +def inject_header_item(): # makes a submodule accessible. + if not 'header_items' in g: + g.header_items = [] + g.header_items.append({ + 'name': 'hello', # link text + 'url': url_for(frontend.name+'.index'), # must use absolute endpoint name! + 'parent': frontend.name, # required, so it gets printed boldface when blueprint is active + 'priority': 1, # higher priority, further left. + }) -- 2.39.3