Thursday, 27 May 2021

How can a flask Addon overwrite a template?

I created a flask addon using "flask fab create-addon".

I would like to change the template appbuilder/general/security/login_oauth.html so I have:

templates
  appbuilder
     general
       security
          login_oauth.html

But when I load the host application my version of login_oauth.html is not loaded. I tried registering a blueprint as in this post with the following code:

from flask import Blueprint
bp = Blueprint('fab_addon_fslogin', __name__, template_folder='templates')

class MyAddOnManager(BaseManager):
    def __init__(self, appbuilder):
        """
        Use the constructor to setup any config keys specific for your app.
        """
        super(MyAddOnManager, self).__init__(appbuilder)
        self.appbuilder.get_app.config.setdefault("MYADDON_KEY", "SOME VALUE")
        self.appbuilder.register_blueprint(bp)

    def register_views(self):
        """
        This method is called by AppBuilder when initializing, use it to add you views
        """
        pass

    def pre_process(self):
        pass

    def post_process(self):
        pass

But register_blueprint(bp) return:

  File "/home/cquiros/data/projects2017/personal/software/superset/addons/fab_addon_fslogin/fab_addon_fslogin/manager.py", line 24, in __init__
    self.appbuilder.register_blueprint(bp)
  File "/home/cquiros/data/projects2017/personal/software/superset/env_superset/lib/python3.8/site-packages/Flask_AppBuilder-3.3.0-py3.8.egg/flask_appbuilder/base.py", line 643, in register_blueprint
    baseview.create_blueprint(
AttributeError: 'Blueprint' object has no attribute 'create_blueprint'

Not much information out there on how to do this. Any clue is appreciated



from How can a flask Addon overwrite a template?

No comments:

Post a Comment