dpgaspar / Flask-AppBuilder

Simple and rapid application development framework, built on top of Flask. includes detailed security, auto CRUD generation for your models, google charts and much more. Demo (login with guest/welcome) - http://flaskappbuilder.pythonanywhere.com/
BSD 3-Clause "New" or "Revised" License
4.69k stars 1.36k forks source link

Is there away to create pure flask views as part of my FAB #136

Closed reffael closed 9 years ago

reffael commented 9 years ago

but with the look&feel of the rest of the pages, using the same permissions, roles, menus and so on.. ?

dpgaspar commented 9 years ago

Yes, using any king of view (BaseView, ModelView ...) create your custom endpoints:

from flask.ext.appbuilder import ModelView
from flask.ext.appbuilder.models.sqla.interface import SQLAInterface

class GroupModelView(ModelView):
    datamodel = SQLAInterface(ContactGroup)
    related_views = [ContactModelView]

    @expose('/mycustomview')
    @has_access
    def mycustomview(self):
        # do whatever you want
        return self.render_template('mycustomview.html')

Then on template extend base:

{% extends "appbuilder/base.html" %}
{% block content %}
      ....
{% endblock %}

This will render you custom view with the menus and bootstrap, and will create an extra permission called 'can mycustomview' on GroupModelView.

reffael commented 9 years ago

thanks, going to try it