Search code examples
pythonrestflaskflask-security

Using flask-security as a part of an REST API


I am currently in the process of building an REST API with flask-security. Fortunately flask-security has a lot of views and templates, which i won't need in my case. I am obviously not able to override them by reimplementing e.g. @app.route('/login') with my own logic.

So the simple question is, how do i disable all the views from flask-security which returns a template?


Solution

  • I don't think that you can disable directly because none of the flask exposed APIs have disabled state. You can customize the views like this below sample:

    Here is the link for reference: Flask Security

    security = Security(app, user_datastore)
    
    # This processor is added to all templates
    @security.context_processor
    def security_context_processor():
        return dict(hello="world")
    
    # This processor is added to only the register view
    @security.register_context_processor
    def security_register_processor():
        return dict(something="else")
    

    Hope it helps.