From b38a9f56e54eb21eec37f40075399961ba82906f Mon Sep 17 00:00:00 2001 From: Gareth Coles Date: Fri, 9 Feb 2018 12:19:55 +0000 Subject: Move from straight app registration to Blueprints (#6) --- pysite/base_route.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'pysite/base_route.py') diff --git a/pysite/base_route.py b/pysite/base_route.py index 916e7fae..8274e66f 100644 --- a/pysite/base_route.py +++ b/pysite/base_route.py @@ -1,5 +1,5 @@ # coding=utf-8 -from flask import Flask, render_template +from flask import Blueprint, render_template from flask.views import MethodView @@ -17,19 +17,19 @@ class RouteView(BaseView): path = None # type: str @classmethod - def setup(cls: "RouteView", app: Flask): + def setup(cls: "RouteView", blueprint: Blueprint): if not cls.path or not cls.name: raise RuntimeError("Route views must have both `path` and `name` defined") - app.add_url_rule(cls.path, view_func=cls.as_view(cls.name)) + blueprint.add_url_rule(cls.path, view_func=cls.as_view(cls.name)) class ErrorView(BaseView): error_code = None # type: int @classmethod - def setup(cls: "ErrorView", app: Flask): + def setup(cls: "ErrorView", blueprint: Blueprint): if not cls.name or not cls.error_code: raise RuntimeError("Error views must have both `name` and `error_code` defined") - app._register_error_handler(None, cls.error_code, cls.as_view(cls.name)) + blueprint.errorhandler(cls.error_code)(cls.as_view(cls.name)) -- cgit v1.2.3