]>
git.gir.st - subscriptionfeed.git/blob - app/example_plugin/__init__.py
2 This is an example Blueprint to base your plugin off of.
3 to use it, add the blueprint's name (e.g. "example_plugin") in
4 config/config.ini, under the [frontend] section, to the modules key (csv).
5 first-named blueprints take precidence (which allows overwriting existing
6 routes from other blueprints).
8 from flask
import Blueprint
, g
, url_for
9 from flask_login
import current_user
11 from ..common
.common
import *
13 frontend
= Blueprint(__name__
.rpartition('.')[2], __name__
)
15 @frontend.route('/hello/')
16 @frontend.route('/hello/<name>')
18 token
= getattr(current_user
, 'token', 'guest') # 'standard' way to get user info when log-in is not required
19 # assume there's some other /hello/world endpoint to handle this special case:
21 return fallback_route(name
)
22 return f
"hello, {name or 'you'} from user {token}!" # note: token is usually not a username, but a random string
24 @frontend.before_app_request
25 def inject_header_item(): # makes a submodule accessible.
26 if not 'header_items' in g
:
28 g
.header_items
.append({
29 'name': 'hello', # link text
30 'url': url_for(frontend
.name
+'.index'), # must use absolute endpoint name!
31 'parent': frontend
.name
, # required, so it gets printed boldface when blueprint is active
32 'priority': 1, # higher priority, further left.