Search code examples
flaskflask-admin

flask-admin when to use @action decorator and when to use @expose decorator


So i am now on a project where i have to customize flask-admin interface. I see two decortors that are important. The @expose decorator and the @action decorator. so my question is, where is the difference between them. For me it looks like they can do the same things. When o use @action and when to use @expose ?


Solution

  • @expose is used for rendering views onto one object, eg show/edit a user.

    Use this decorator to expose views in your view classes. Link to documentation

    @action is used for rending views on more than one object, eg Adding a user to a course (school).

    Use this decorator to expose actions that span more than one entity (model, file, etc) Link to documentation.

    For more understanding (im not an expert) read the Flask-admin documentation. It is highly recommended that you have a read and understand it, especially if you have joined a project that involves using flask-admin.