Allow render_template to be overwritten #179

Closed
rochacbruno opened this Issue Nov 7, 2013 · 0 comments

2 participants

@rochacbruno

HI,

I am using a Flask-Themes application https://github.com/pythonhub/quokka-themes

I can customize the theme for almost all apps, even for Flask-Admin I can do it by extending the main class

from flask.ext.admin import Admin

class MyCustomAdmin(Admin):
    def render_template(self, *args, **kwargs):
        # here I load my theme template

But I was trying to do the same with Security

from flask.ext.security import Security

class MyCustomSecurity(Security):
    def render_template(self, *args, **kwargs):
        # here I load my theme template

But I figured out that Security main class does not expose a render method to be ovewritten.

It is now being done directly by the views, so I suggest to have a method and use this for rendering templates, or maybe have a config variable.

SECURITY_RENDER = 'somewhere.module:render_template'

So with the above setting you can do in views.py

from werkzeug.utils import import_string
render_template = import_string(config.get('SECURITY_RENDER'))

Having its default to a normal render_template from Flask.

But I prefer the first case when the class expose a render method to be overwritten.

By now I will create a fork and implement that for my specific case.. If I got some idea I will send a PR.

What do you thing about it? @mattupstate

@rochacbruno rochacbruno added a commit to quokkaproject/quokka that referenced this issue Nov 7, 2013
@rochacbruno rochacbruno Forked flask-security to support themes mattupstate/flask-security#179
installing security from pythonhub repo while not merged or found another
solution
deed021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment