flask_jsonrpc.contrib.browse package¶
Module contents¶
- register_middleware(name)[source]¶
Register a browse middleware.
- If a middleware returns:
True: the middleware will be kept for after_request and teardown_request processing.
False: the middleware will be skipped for after_request and teardown_request processing.
A Response: the response will be returned immediately, skipping further processing.
- Parameters:
name (str) – The name of the middleware.
- Returns:
The middleware decorator.
- Return type:
Examples
Inject a custom header into the response using a middleware:
>>> import pytest >>> pytest.skip('The global context causes issues with testing.') >>> >>> from flask import Flask, Response >>> from flask_jsonrpc.contrib.browse import JSONRPCBrowse, register_middleware >>> >>> app = Flask(__name__) >>> browse = JSONRPCBrowse(app) >>> >>> @register_middleware('example_middleware') ... def example_middleware(request): ... response = yield ... response.headers['X-Example'] = 'Value' ... yield response >>> >>> with app.test_client() as client: ... response = client.get('/api/browse/') ... assert response.headers.get('X-Example') == 'Value'
- class JSONRPCBrowseTemplateLoader(app_jinja_loader, browse_jinja_loader)[source]¶
Bases:
BaseLoaderCustom Jinja2 template loader that tries to load templates from the application first, then falls back to the browse templates.
- Parameters:
app_jinja_loader (jinja2.BaseLoader) – The application’s Jinja2 template loader.
browse_jinja_loader (jinja2.BaseLoader) – The browse’s Jinja2 template loader.
- app_jinja_loader¶
The application’s Jinja2 template loader.
- Type:
jinja2.BaseLoader
- browse_jinja_loader¶
The browse’s Jinja2 template loader.
- Type:
jinja2.BaseLoader
- class JSONRPCBrowse(app=None, url_prefix='/api/browse', base_url=None)[source]¶
Bases:
objectJSON-RPC Browse extension for Flask applications.
- Parameters:
- jsonrpc_sites¶
The set of registered JSON-RPC sites
Examples
>>> from flask import Flask >>> from flask_jsonrpc import JSONRPCBlueprint >>> from flask_jsonrpc.contrib.browse import JSONRPCBrowse >>> >>> app = Flask(__name__) >>> jsonrpc = JSONRPCBlueprint('example', __name__) >>> browse = JSONRPCBrowse(app, url_prefix='/api/browse') >>> browse.register_jsonrpc_site(jsonrpc)
- init_app(app)[source]¶
Initialize the JSON-RPC Browse extension with a Flask application.
Middlewares for before_request, after_request, and teardown_request are registered.
- Parameters:
app (flask.Flask) – The Flask application.
self (Self)
- Return type:
None
Examples
>>> from flask import Flask >>> from flask_jsonrpc.contrib.browse import JSONRPCBrowse >>> >>> app = Flask(__name__) >>> browse = JSONRPCBrowse() >>> browse.init_app(app)
- register_jsonrpc_site(jsonrpc_site)[source]¶
Register a JSON-RPC site with the browse extension.
- Parameters:
jsonrpc_site (flask_jsonrpc.site.JSONRPCSite) – The JSON-RPC site to register.
self (Self)
- Return type:
None
- get_browse_title()[source]¶
Get the browse title.
Register a custom title by setting BROWSE_TITLE in your settings or overriding this method.
- get_browse_title_url()[source]¶
Get the browse title URL.
Register a custom title URL by setting BROWSE_TITLE_URL in your settings or overriding this method.
- get_browse_subtitle()[source]¶
Get the browse subtitle.
Register a custom subtitle by setting BROWSE_SUBTITLE in your settings or overriding this method.
- get_browse_description()[source]¶
Get the browse description.
Register a custom description by setting BROWSE_DESCRIPTION in your settings or overriding this method.
- get_browse_fork_me_button_enabled()[source]¶
Check if the “Fork me on GitHub” button is enabled.
Register the button state by setting BROWSE_FORK_ME_BUTTON_ENABLED in your settings or overriding this method.
- get_browse_media_css()[source]¶
Get the browse media CSS files.
Register custom CSS files by setting BROWSE_MEDIA_CSS in your settings or overriding this method.
- get_browse_media_js()[source]¶
Get the browse media JS files.
Register custom JS files by setting BROWSE_MEDIA_JS in your settings or overriding this method.
Get the browse dashboard menu name.
Register a custom dashboard menu name by setting BROWSE_DASHBOARD_MENU_NAME in your settings or overriding this method.
- get_browse_dashboard_partial_template()[source]¶
Get the browse dashboard partial template.
Register a custom dashboard partial template by setting BROWSE_DASHBOARD_PARTIAL_TEMPLATE in your settings or overriding this method.
- get_browse_login_template()[source]¶
Get the browse login template.
Register a custom login template by setting BROWSE_LOGIN_TEMPLATE in your settings or overriding this method.
- get_browse_logout_template()[source]¶
Get the browse logout template.
Register a custom logout template by setting BROWSE_LOGOUT_TEMPLATE in your settings or overriding this method.
- vf_json_packages()[source]¶
Get the JSON representation of the package tree.
Ignores methods starting with ‘rpc.’ as they are reserved for JSON-RPC 2.0 specification system extensions.
- Returns:
The JSON representation of the package tree.
- Return type:
flask.typing.ResponseReturnValue
- Parameters:
self (Self)
- vf_json_method(method_name)[source]¶
Get the JSON representation of a specific method.
- Parameters:
method_name (str) – The name of the method.
self (Self)
- Returns:
The JSON representation of the method or a 404 error if not found.
- Return type:
flask.typing.ResponseReturnValue
Render the menu tree partial template.