Application Startup Hooks¶
Application startup hooks are called when the application is created,
either through a WSGI server (uWSGI or gunicorn for example) or by
the flaskbb
command.
Unless noted, all FlaskBB hooks are called after the relevant builtin
FlaskBB setup has run (e.g. flaskbb_load_blueprints
is called after
all standard FlaskBB blueprints have been loaded).
The hooks below are listed in the order they are called.
-
flaskbb.plugins.spec.
flaskbb_extensions
(app)[source]¶ Hook for initializing any plugin loaded extensions.
-
flaskbb.plugins.spec.
flaskbb_load_blueprints
(app)[source]¶ Hook for registering blueprints.
Parameters: app – The application object.
-
flaskbb.plugins.spec.
flaskbb_jinja_directives
(app)[source]¶ Hook for registering jinja filters, context processors, etc.
Parameters: app – The application object.
-
flaskbb.plugins.spec.
flaskbb_request_processors
(app)[source]¶ Hook for registering pre/post request processors.
Parameters: app – The application object.
-
flaskbb.plugins.spec.
flaskbb_errorhandlers
(app)[source]¶ Hook for registering error handlers.
Parameters: app – The application object.
-
flaskbb.plugins.spec.
flaskbb_load_post_markdown_class
(app)[source]¶ Hook for loading a mistune renderer child class in order to render markdown on posts and user signatures. All classes returned by this hook will be composed into a single class to render markdown for posts.
Since all classes will be composed together, child classes should call super as appropriate and not add any new arguments to __init__ since the class will be insantiated with predetermined arguments.
Example:
class YellingRenderer(mistune.Renderer): def paragraph(self, text): return super(YellingRenderer, self).paragraph(text.upper()) @impl def flaskbb_load_post_markdown_class(): return YellingRenderer
Parameters: app (Flask) – The application object associated with the class if needed
-
flaskbb.plugins.spec.
flaskbb_load_nonpost_markdown_class
(app)[source]¶ Hook for loading a mistune renderer child class in order to render markdown in locations other than posts, for example in category or forum descriptions. All classes returned by this hook will be composed into a single class to render markdown for nonpost content (e.g. forum and category descriptions).
Since all classes will be composed together, child classes should call super as appropriate and not add any new arguments to __init__ since the class will be insantiated with predetermined arguments.
Example:
class YellingRenderer(mistune.Renderer): def paragraph(self, text): return super(YellingRenderer, self).paragraph(text.upper()) @impl def flaskbb_load_nonpost_markdown_class(): return YellingRenderer
Parameters: app (Flask) – The application object associated with the class if needed
-
flaskbb.plugins.spec.
flaskbb_load_post_markdown_plugins
(plugins, app)[source]¶ Hook for loading mistune renderer plugins used when rendering markdown on posts and user signatures. Implementations should modify the plugins list directly.
Example of adding plugins:
from mistune.plugins import plugin_abbr, plugin_table @impl def flaskbb_load_post_markdown_plugins(plugins): # add the built-in mistune table and abbr plugins plugins.extend([plugin_abbr, plugin_table])
Example of removing plugins:
from flaskbb.markup import plugin_userify @impl def flaskbb_load_post_markdown_plugins(plugins): try: # remove the FlaskBB user mention link plugin plugins.remove(plugin_userify) except ValueError: # other FlaskBB plugins might beat you to removing a plugin, # which is not an error. You should not raise an exception in # this case. pass
Parameters: - plugins (list) – List of mistune plugins to load.
- app (Flask) – The application object.
See also
- https://mistune.readthedocs.io/en/v2.0.2/advanced.html#create-plugins
- Mistune plugin documentation.
plugin_userify
- FlaskBB-provided plugin that links user mentions to their profiles.
DEFAULT_PLUGINS
- List of plugins loaded by default.
flaskbb_load_nonpost_markdown_plugins()
- Hook to modify the list of plugins for markdown rendering in non-post areas.
-
flaskbb.plugins.spec.
flaskbb_load_nonpost_markdown_plugins
(plugins, app)[source]¶ Hook for loading mistune renderer plugins used when rendering markdown in locations other than posts, for example in category or forum descriptions. Implementations should modify the plugins list directly.
See
flaskbb_load_post_markdown_plugins()
for more details.Parameters: - plugins (list) – List of mistune plugins to load.
- app (Flask) – The application object.
-
flaskbb.plugins.spec.
flaskbb_additional_setup
(app, pluggy)[source]¶ Hook for any additional setup a plugin wants to do after all other application setup has finished.
For example, you could apply a WSGI middleware:
@impl def flaskbb_additional_setup(app): app.wsgi_app = ProxyFix(app.wsgi_app)
Parameters: - app – The application object.
- pluggy – The pluggy object.