Python flask.blueprints.Blueprint() Examples

The following are 8 code examples of flask.blueprints.Blueprint(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module flask.blueprints , or try the search function .
Example #1
Source File: core.py    From swagger-ui-py with Apache License 2.0 6 votes vote down vote up
def _sanic_handler(self):
        from sanic import response
        from sanic.blueprints import Blueprint

        swagger_blueprint = Blueprint('swagger_blueprint', url_prefix=self._url_prefix)

        @swagger_blueprint.get('/')
        async def swagger_blueprint_doc_handler(request):
            return response.html(self.doc_html)

        if self._editor:
            @swagger_blueprint.get('/editor')
            async def swagger_blueprint_editor_handler(request):
                return response.html(self.editor_html)

        @swagger_blueprint.get('/swagger.json')
        async def swagger_blueprint_config_handler(request):
            return response.json(self.get_config(request.host))

        swagger_blueprint.static('/', str(self.static_dir))
        self._app.blueprint(swagger_blueprint) 
Example #2
Source File: core.py    From swagger-ui-py with Apache License 2.0 6 votes vote down vote up
def _quart_handler(self):
        from quart import Blueprint, request
        from quart.json import jsonify

        swagger_blueprint = Blueprint(
            'swagger_blueprint', __name__, url_prefix=self._url_prefix,
            static_url_path='', static_folder='', root_path=self.static_dir
        )

        @swagger_blueprint.route('/', methods=['GET'])
        async def swagger_blueprint_doc_handler():
            return self.doc_html

        if self._editor:
            @swagger_blueprint.route('/editor', methods=['GET'])
            async def swagger_blueprint_editor_handler():
                return self.editor_html

        @swagger_blueprint.route('/swagger.json', methods=['GET'])
        async def swagger_blueprint_config_handler():
            return jsonify(self.get_config(request.host))

        self._app.register_blueprint(blueprint=swagger_blueprint, url_prefix=self._url_prefix) 
Example #3
Source File: liveserverfixture.py    From quay with Apache License 2.0 6 votes vote down vote up
def apply_blueprint_to_app(self, app):
        """
        Applies a blueprint to the app, to support invocation from this executor.
        """
        testbp = Blueprint("testbp", __name__)

        def build_invoker(fn_name, fn):
            path = "/" + fn_name

            @testbp.route(path, methods=["POST"], endpoint=fn_name)
            def _(**kwargs):
                arg_values = request.get_json()["args"]
                return fn(*arg_values)

        for fn_name, fn in self.funcs.items():
            build_invoker(fn_name, fn)

        app.register_blueprint(testbp, url_prefix="/__test") 
Example #4
Source File: __init__.py    From learning-python with MIT License 5 votes vote down vote up
def register_routes(app):
    """Register routes."""
    from . import controllers
    from flask.blueprints import Blueprint

    for module in _import_submodules_from_package(controllers):
        bp = getattr(module, 'bp')
        if bp and isinstance(bp, Blueprint):
            app.register_blueprint(bp) 
Example #5
Source File: __init__.py    From Flask-Boost with MIT License 5 votes vote down vote up
def register_routes(app):
    """Register routes."""
    from . import controllers
    from flask.blueprints import Blueprint

    for module in _import_submodules_from_package(controllers):
        bp = getattr(module, 'bp')
        if bp and isinstance(bp, Blueprint):
            app.register_blueprint(bp) 
Example #6
Source File: core.py    From swagger-ui-py with Apache License 2.0 5 votes vote down vote up
def _flask_handler(self):
        from flask import request, jsonify
        from flask.blueprints import Blueprint

        swagger_blueprint = Blueprint(
            'swagger_blueprint', __name__, url_prefix=self._url_prefix,
            static_folder=self.static_dir, static_url_path='/'
        )

        @swagger_blueprint.route(r'')
        def swagger_blueprint_doc_handler():
            return self.doc_html

        @swagger_blueprint.route(r'/')
        def swagger_blueprint_doc_v2_handler():
            return self.doc_html

        @swagger_blueprint.route(r'/swagger.json')
        def swagger_blueprint_config_handler():
            return jsonify(self.get_config(request.host))

        if self._editor:
            @swagger_blueprint.route(r'/editor')
            def swagger_blueprint_editor_handler():
                return self.editor_html

        self._app.register_blueprint(swagger_blueprint) 
Example #7
Source File: index.py    From rd-usb with GNU General Public License v3.0 5 votes vote down vote up
def register(self):
        blueprint = Blueprint("index", __name__, template_folder="templates")
        blueprint.add_url_rule("/", "default", self.render_default)
        blueprint.add_url_rule("/data", "data", self.render_data)
        blueprint.add_url_rule("/graph", "graph", self.render_graph)
        blueprint.add_url_rule("/graph.json", "graph_data", self.render_graph_data)
        blueprint.add_url_rule("/ble", "ble", self.render_ble)
        blueprint.add_url_rule("/serial", "serial", self.render_serial)
        blueprint.context_processor(self.fill)
        return blueprint 
Example #8
Source File: app.py    From cmdb with GNU General Public License v2.0 5 votes vote down vote up
def register_blueprints(app):
    for item in getmembers(api.views):
        if item[0].startswith("blueprint") and isinstance(item[1], Blueprint):
            app.register_blueprint(item[1])