Open lnlrbr opened 6 years ago
Hi, @LionelR I also face the issue just like you.
I find out that in version 3.0.0's flask_security.Security init_app
function is a little bit different from __init__
.
It won't assign self._state
when using init_app
way, but it'll return state object for you.
So, I guess, that's why the getattr
would never find context_processor
attribute in self._state
. 😢
For now, I found there are two ways to fix this issue,
init_app
return value
secur = security.webui_security.init_app(app=app, datastore=security.user_datastore)
@secur.context_processor
def security_context_processor():
...
init_app
security = app.extension['security']
@security.context_processor
def security_context_processor():
...
Or you can just use the develop branch code.
I saw someone add self._state = state = _get_state(app, datastore, **kwargs)
to fix this problem.
(CODE LINK)
Hope it will help you.
Any update on this? I still have the same issue (following @LionelR's approach) ...
security_state = security.init_app(app,user_datastore)
security._state = security_state
Please consider moving to: https://github.com/Flask-Middleware/flask-security
which is my updated and maintained fork. The fix mentioned above is there.
i am use template: {% set admin_base_template = security.admin_base_template %} {% set admin_view = security.admin_view %} {% set get_url = security.get_url %} {% set h = security.h %} {% extends 'admin/master.html' %}
use in: security.init_app(app, user_datastore, admin_base_template=admin.base_template, admin_view=admin.index_view, h=admin_helpers, get_url=url_for)
Work! Not use @...context_processor
I try to use flask_security with flask_admin, but at start up there's a problem with the context_processor:
My setup:
from knmx import config from knmx import security from knmx.db import models from knmx.views import api, admin, webui, schemas def create_app(extra_config=None): app = Flask(name.split('.')[0]) app.config.from_object(config.DefaultConfig) register_extensions(app=app)
def register_extensions(app): models.db.init_app(app=app) security.webui_security.init_app(app=app, datastore=security.user_datastore) security.jwt.init_app(app=app) admin.admin.init_app(app=app)
admin = Admin()
@webui_security.context_processor def security_context_processor(): return dict( admin_base_template=admin.base_template, admin_view=admin.index_view, h=admin_helpers, get_url=url_for )